[Explanations] luogu_P2059_ card game (state design / probability dp

You need to design a state in which the dead do not record, in fact, the number of people on location and nothing to do after the dead, and the probability of each location so better record

Set $ ​​f [i] [j] $ to a total of $ i $ individuals, from the first person of the $ j $ personal probability PLAY back, if nothing more than to see the transfer of sub-problems, choose a card to kill the village people in fact, after only the i-1 $ $ individual, this time winning odds can be combined with each point corresponding to the position,

#include<bits/stdc++.h>
using namespace std;
const int maxn=59;
int n,m,a[maxn];
double f[maxn][maxn];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)scanf("%d",&a[i]);
    f[1][1]=1.0;
    for(int i=2;i<=n;i++){
        for(int k=1;k<=m;k++){
            int p=(a[k]%i==0)?i:a[k]%i;//死人 
            for(int j=1;j<=i-1;j++){
                p++;
                if(p>i)p=1;
                f[i][p]+=f[i-1][j]/(1.0*m);
            }
        }
    }
    for(int i=1;i<=n;i++)
    printf("%.2lf%% ",f[n][i]*100.0);
}

 

Guess you like

Origin www.cnblogs.com/superminivan/p/11514359.html