Portal
This question will not be transferred at the beginning ...... Because the status is set incorrectly.
Let's take a look at the operations on Joseph's problem. If DP [I] [J] is set, it indicates the probability of winning J people starting from the banker when I am there. In this case, we only need to enumerate each card, in this case, the probability of each person to win can be introduced by the I-1 of individuals, because in fact, the elimination of a person is equivalent to moving the queue forward several places, but the winner will not change.
The probability of each card is the same, so we can obtain the DP equation:
DP [I] [J] + = (DP [I-1] [(j-C [k] + I) % I])/m.
The code is very short. Note that the last answer must be multiplied by 100.
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<cmath>#include<set>#include<queue>#define rep(i,a,n) for(int i = a;i <= n;i++)#define per(i,n,a) for(int i = n;i >= a;i--)#define enter putchar(‘\n‘)using namespace std;typedef long long ll;const int M = 10005;const ll INF = 1000000009;const int mod = 9397;int read(){ int ans = 0,op = 1; char ch = getchar(); while(ch < ‘0‘ || ch > ‘9‘) { if(ch == ‘-‘) op = -1; ch = getchar(); } while(ch >= ‘0‘ && ch <= ‘9‘) { ans *= 10; ans += ch - ‘0‘; ch = getchar(); } return ans * op;}int a[M],n,m;double dp[1005][1005];int main(){ n = read(),m = read(); rep(i,1,m) a[i] = read(); dp[1][1] = 1.0; rep(i,2,n) rep(j,1,i) rep(k,1,m) { int c = (a[k] % i) ? a[k] % i : i; if(c > j) dp[i][j] += dp[i-1][i-c+j] / (double)m * 1.0; else if(c < j) dp[i][j] += dp[i-1][j-c] / (double)m * 1.0; } rep(i,1,n) printf("%.2lf%% ",dp[n][i] * 100.0);enter; return 0;}
[Jloi2013] card games