Compare it routine
Since the optimal strategy to use, difficult to think backwards,
That is expected to generate a positive return after the election, the election is not negative returns.
I confidently presented, then immediately wrote the above sentence and then lost WA (my dishes ah). The correct one should be:
That is, after the election expected to produce larger returns than not vote on the election, otherwise not vote.
DP can then be a conventional pressure-like.
#include<iostream> #include<cstdio> using namespace std; const int maxn = 105; double dp[maxn][(1<<15)+5], ans; int n, able[maxn], w[maxn], k; void do_it(int x) { int i, j, t; for(i=0; i <= (1<<n)-1; i++) { for(j=1; j <= n; j++) { if((able[j] & i) == able[j]) { dp[x][i]+=max(dp[x+1][i], (dp[x+1][(i|(1<<j-1))]+w[j]))/(double)n; } else dp[x][i]+=dp[x+1][i]/(double)n; } //cout<<x<<' '<<i<<' '<<dp[x][i]<<endl; } return; } int main() { ios::sync_with_stdio(false); int i, t; cin>>k>>n; for(i=1; i <= n;i ++ ) { development>>w[i]>>t; while(t != 0) { able[i]=(able[i]|(1<<t-1)); cin>>t; } } for(i=k; i >= 1; i--) do_it(i); printf("%.6lf", dp[1][0]); return 0; }