首页 > 代码库 > cf 261B.Maxim and Restaurant

cf 261B.Maxim and Restaurant

什么什么期望的,不会!

(题解http://blog.sina.com.cn/s/blog_140e100580102wj4e.html(看不懂))

#include<bits/stdc++.h>
#define LL long long
#define LD long double  
#define  N 100005
using namespace std;
inline int ra()
{
    int x=0,f=1; char ch=getchar();
    while (ch<0 || ch>9) {if (ch==-) f=-1; ch=getchar();}
    while (ch>=0 && ch<=9) {x=x*10+ch-0; ch=getchar();}
    return x*f;
}
LD C[55];
LD dp[55][55][105];
int a[55];
int main()
{
    int n=ra();
    C[0]=1;
    for (int i=1; i<=n; i++)
    {
        C[i]=C[i-1]*(LD)i;
        a[i]=ra();
    }
    sort(a+1,a+n+1);
    int m=ra();
    dp[1][0][0]=1; dp[1][1][a[1]]=1;
    for (int i=1; i<=n; i++)
        for (int j=0; j<=i; j++)
            for (int k=0; k<=m; k++)
            {
                dp[i+1][j+1][k+a[i+1]]+=dp[i][j][k];
                dp[i+1][j][k]+=dp[i][j][k];
            }
    LD res=0;
    for (int j=1; j<=n; j++)
        for (int k=0; k<=m; k++)
        {
            res+=dp[n][j][k]*(C[j]*C[n-j]);
            cout<<j<<"  "<<k<<"   "<<dp[n][j][k]<<endl;
        }
    res=res/C[n];
    cout<<res;
    return 0;
} 

 

cf 261B.Maxim and Restaurant