[JLOI2013] Card Game [probability dp]

P2059 [JLOI2013] Card Game

Dynamic Programming and Probability

Joseph deformation problems: m cards, each randomly draw a card, the card numbers mi, from 0 to mi-1 reported that the number of people out and asked everyone probability of winning.
1 <= n, the numbers m, card <= 50
About Joseph recursive problem can be obtained x n people who fixed the time of victory
f [i] i represents individuals who win, f [i] = (f [i-1] + x)% n
Consider the individual i in the first round, out after the individual x, from all x, x + 1 ... 0,1, x-2 renumbered 0,1 ... n-2, and then becomes a smaller problem, while the last winner in the first round y should be located at a position (y + x)% n of
This question, it is assumed Fi [i] [j] represents the individual time i, the probability of winning the personal j, fi [i] [j] = sigma ((k + mi)% i == j) f [i -1] [k] / m, the initialization fi [1] [0] = 100 (in percent), the final output fi [n] [] on it.
Can → f [i + 1] from the f [i] [j] [(j + x)% (i + 1)] i.e. when (k + mi)% i == j when
 From the simple to the general push a person to think when the success rate is 100% sure and then again push
 
#include<bits/stdc++.h>
using namespace std;
#define Max(x,y) (x)>(y)?(x):(y)
#define Min(x,y) (x)>(y)?(y):(x)
#define rg register
#define ll long long
const int N=100+5,M=0,inf=0x3f3f3f3f,P=99999997;
int n,m,a[N];
double f[N][N];
template <class t>void rd(t &x){
    x=0;int w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=w?-x:x;
}


int main(){
//    freopen("in.txt","r",stdin);
    rd(n),rd(m);
    for(int i=1;i<=m;++i) rd(a[i]);
    f[1][0]=f[1][1]=100.0;
    for(int i=2;i<=n;++i)
    for(int j=1;j<=i;++j){
        for(int k=1;k<=m;++k){
        int x=(a[k]%i)?a[k]%i:i;
        if(x<j) f[i][j]+=f[i-1][j-x]/m;
        else if(x>j) f[i][j]+=f[i-1][i-(x-j)]/m;
            
        }
    }
    for(int i=1;i<=n;++i) printf("%.2f%% ",f[n][i]);
    return 0;
}
 

 

Guess you like

Origin www.cnblogs.com/lxyyyy/p/11240946.html