HDU 5045 Contest expect + pressure dp 2014 ACM/ICPC Asia Regional Shanghai Online, hduicpc

Source: Internet
Author: User

HDU 5045 Contest expect + pressure dp 2014 ACM/ICPC Asia Regional Shanghai Online, hduicpc

Question:

Given n people m questions

The n * m matrix below indicates the probability of each person solving each question.


We can get a set of m values {1, 2, 3, 1, 2}

Indicates who solved each question.

There are many sets, and there is an expectation for this set, and the set with the largest expectation (what is the expectation)

One restriction: This is invalid for the set {, 1} (that is, the question from [1, n] must be 1-n, and then [n + 1, 2n] question is also an arrangement)

Then press dp

#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <vector>using namespace std;typedef long long ll;const int M= 1000 +2;const int N= 10+2;const int S= (1 << 10) + 10;double d[M][S], p[N][M];int main() {    int cas, mx, n, m, to;    scanf("%d", &cas);    for(int T= 1; T<= cas; ++T) {        scanf("%d%d", &n, &m);        for (int i = 0; i < n; ++i)            for (int j = 0; j < m; ++j)                scanf("%lf", &p[i][j]);        mx = (1 << n) - 1;        memset(d, 0, sizeof d);        d[0][0] = 0;        for (int i = 0; i < m; ++i) {            int s = (1 << (i % n)) - 1;            while (s < mx) {                int x = s & -s;                int y = s + x;                for (int k = 0; k < n; ++k)                    if (!(s >> k & 1)) {                        to = s | (1 << k);                        if (to == mx)                            to = 0;                        d[i + 1][to] = max(d[i + 1][to], d[i][s] * (1.0 - p[k][i]) + (d[i][s] + 1) * p[k][i]);                    }                if (s == 0) break;                s = ((s & ~y) / x >> 1) | y;            }        }        double ans = 0;        for (int i = 0; i < mx; ++i)            ans = max(ans, d[m][i]);        printf("Case #%d: %.5f\n", T, ans);    }    return 0;}



2012 how many teams are ACM/ICPC Asia Regional Chengdu Online?

130 teams
 
The 2009 ACM-ICPC Asia Ningbo Regional Online Contest-D

Haha ...... I am also doing this. Let's talk about it, that is, using a diamond (defined as a diamond in the distance from Manhattan), a square with 45 degrees of rotation, a nested one, and finding the center of the circle.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.