[Jloi2013] card games

Source: Internet
Author: User

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

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.