HDU 5159 Card (组合数学)

所有的组合中包含某个数的次数对于所有的数来说是相同的,那么就求出这个次数乘以所有数的和然后除以总的组合次数就可以了。开始想复杂了。。。

可以先预处理下,然后直接输出。

代码如下:

#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
#define LL __int64
#define pi acos(-1.0)
const int mod=100000000;
const int INF=0x3f3f3f3f;
const double eqs=1e-8;
double dp[100001][6];
int main()
{
        int x, b, t, i, num=0, j, k;
        double ans1, ans2;
        for(i=1; i<=5; i++) {
                dp[1][i]=1;
        }
        for(i=2; i<=100000; i++) {
                dp[i][1]=dp[i-1][1]+i;
                for(j=2; j<=5; j++) {
                        ans1=ans2=1;
                        for(k=1; k<j; k++) {
                                ans1*=i;
                        }
                        for(k=1;k<j;k++){
                            ans2*=(i-1);
                        }
                       dp[i][j]=(i*ans1-(i-1)*ans2)*(i*1.0*(i+1)/2.0);
                }
        }
        scanf("%d",&t);
        while(t--) {
                scanf("%d%d",&x,&b);
                num++;
                printf("Case #%d: ",num);
                double ans=1;
                for(i=0; i<b; i++) {
                        ans*=x;
                }
                printf("%.3f\n",dp[x][b]/ans);
        }
        return 0;
}
时间: 2024-10-10 08:48:47

HDU 5159 Card (组合数学)的相关文章

HDU 5159 Card

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解: 考虑没一个数的贡献,一个数一次都不出现的次数是(x-1)^b,而总的排列次数是x^b,所以每一个数有贡献的次数都是x^b-(x-1)^b,所以最后推导的公式就是: (x^b-(x-1)^b)*(1+2+...+x)/(x^b)=(1-((x-1)/x)^b)*(1+x)*x/2 代码: 1 #include<iostream> 2 #include<cstdio> 3

hdu 5159 Card (期望)

Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the card which is numbered i(1<=i<=x) is i. Every round BieBie picks one card out of the x cards,then puts it back. He does the same operation for b round

HDU 5159 Card( 计数 期望 )

Card Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 191    Accepted Submission(s): 52Special Judge Problem Description There are x cards on the desk, they are numbered from 1 to x. The score o

hdu 6025 card card card(双指针)

题目链接:hdu 6025 card card card 题意: 有n对数(a,b),现在你可以将前x对(a,b)移到尾部. 操作完后,现在定义sum=ai-bi (1,x),当sum<0时,当前的价值为Σai (1<=i<=x-1). 问你移动前多少对(a,b),使得价值最大,如果有多个答案,输出最小的那个. 题解: 复制一份,双指针模拟一下就行了. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<

HDU 3722 Card Game(KM最大匹配)

HDU 3722 Card Game 题目链接 题意:给定一些字符串,每次可以选两个a,b出来,a的前缀和b的后缀的最长公共长度就是获得的值,字符串不能重复选,问最大能获得多少值 思路:KM最大匹配,两两串建边,跑最大匹配即可 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MAXNODE

HDU 4159 Indomie ( 组合数学 )

HDU 4159 Indomie ( 组合数学 ) #include <cstdio> typedef __int64 LL; #define MAXN 101 int n, s; LL po[ MAXN ]; void init() { po[0] = 1; for( int i = 1; i < MAXN; ++i ) po[i] = po[i-1] * 2; } double CC( int n, int m ) { double res = 1; for( int i = 0;

HDU 4336 Card Collector(动态规划-概率DP)

Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award. As a

hdu 4336 Card Collector

Card Collector http://acm.hdu.edu.cn/showproblem.php?pid=4336 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Special Judge Problem Description In your childhood, do you crazy for collecting the beautiful cards in

hdu 5159(概率)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5159 题解:假设在 x 张牌中选b张牌,那么有 x^b 种选法,如果在 (x-1) 张牌中选 b 张牌,那么有 (x-1)^b 种选法,所以第 i 张牌出现的概率是 (x^b-(x-1)^b)/x^b 再对每张牌乘上牌面的值即是期望. #include<stdio.h> #include<iostream> #include<string.h> #include <