题目链接

想了挺久,枚举每一件物品,当做关键物品,假设再加这一件物品,就>=c了,把剩下的物品背一下包,dp[i][j]表示i个物品可以组成重量j的个数。

这样就可以知道前面放i件,后边肯定放n-i-1件,乱搞搞,算double,边乘边算保证不要越界。最后注意,LL和sum <= c的时候情况。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL __int64
LL dp[][][];
int p[];
int main()
{
int i,j,k,u,v,n,c,s1,s2,sum;
double ans = ;
scanf("%d",&n);
sum = ;
for(i = ; i <= n; i ++)
{
scanf("%d",&p[i]);
sum += p[i];
}
scanf("%d",&c);
if(sum <= c)
{
printf("%d\n",n);
return ;
}
for(i = ; i <= n; i ++)
{
memset(dp,,sizeof(dp));
dp[][][] = ;
s1 = ;
s2 = ;
for(j = ; j <= n; j ++)
{
if(i == j) continue;
for(k = ; k < j; k ++)
{
for(u = ; u <= ; u ++)
dp[s2][k][u] = dp[s1][k][u];
}
for(k = ; k < j; k ++)
{
for(u = ; u < ; u ++)
{
if(dp[s1][k][u])
{
if(u+p[j] <= )
dp[s2][k+][u+p[j]] += dp[s1][k][u];
}
}
}
swap(s1,s2);
}
for(j = ; j < c; j ++)
{
if(j + p[i] >= c)
{
for(k = ; k < n; k ++)
{
if(dp[s1][k][j] == ) continue;
double temp = dp[s1][k][j];
for(u = ,v = k+;u <= n-k-;u ++,v++)
temp *= u*1.0/v;
temp /= n;
if(j + p[i] == c)
ans += temp*(k+);
else
ans += temp*k;
}
}
}
}
printf("%lf\n",ans);
return ;
}

Codeforces Round #160 (Div. 2) D. Maxim and Restaurant(DP)的更多相关文章

  1. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  2. Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)

    Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...

  3. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  4. Codeforces Round #160 (Div. 2)

    A. Roma and Lucky Numbers 暴力计算. B. Roma and Changing Signs 每次取最小值改变正负,优先队列维护. C. Maxim and Discounts ...

  5. Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心

    D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...

  6. Codeforces Round #374 (Div. 2) D. Maxim and Array —— 贪心

    题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds ...

  7. Codeforces Round #374 (Div. 2) D. Maxim and Array 线段树+贪心

    D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #374 (Div. 2) D. Maxim and Array

    传送门 分析:其实没什么好分析的.统计一下负数个数.如果负数个数是偶数的话,就要尽量增加负数或者减少负数.是奇数的话就努力增大每个数的绝对值.用一个优先队列搞一下就行了. 我感觉这道题的细节极为多,非 ...

  9. Codeforces Round #160 (Div. 2)---A. Roma and Lucky Numbers

    Roma and Lucky Numbers time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. 【转载】 Python动态生成变量

    用Python循环创建多个变量, 如创建 a1=   .a2=   .a3=   .a4=   .a5=    或  self.a1=    .self.a2=   . self.a3= 一. 可以通 ...

  2. 无废话ExtJs 入门教程四[表单:FormPanel]

    无废话ExtJs 入门教程四[表单:FormPanel] extjs技术交流,欢迎加群(201926085) 继上一节内容,我们在窗体里加了个表单.如下所示代码区的第28行位置,items:form. ...

  3. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU2205 又见回文(区间DP)

    题意:给定两个字符串(可能为空串),求这两个串交叉组成新串的子串中的回文串的最大长度. 布尔型变量dp[i][j][k][l]表示串a从i到j,b从k到l能否组成新串,初始化为false,则采取区间动 ...

  5. 企业QQ 增加在线交谈链接

    企业QQ的在线交流链接跟普通QQ的在线交流不一样,普通QQ的在线交流,可以在http://shang.qq.com/v3/widget.html生成:企业qq的链接可以按以下步骤添加: 第一步:引入企 ...

  6. 关于socket——SO_SNDBUF and SO_RECVBUF

    转自:http://blog.csdn.net/wf1982/article/details/38871521 参见 http://stackoverflow.com/questions/425741 ...

  7. VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网的三种方法介绍

    转自:http://www.jb51.net/network/98820.html 如何真正的实现VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网   环境:WIN7旗舰版,台式机,U盘无 ...

  8. 在Salesforce中通过dataloadercliq调用data loader来批量处理数据

    上一篇文章讲到,通过data loader去批量处理数据,那么这篇文章将主要讲解在Salesforce中通过dataloadercliq调用data loader来批量处理数据. 1): CLIq文件 ...

  9. How to use Ajax on Visualforce page on Salesforce platform

    Just use Ajax pattern to call object data from server on visualforce page. Following is the Asynchro ...

  10. java线程之——synchronized的注意细节

    我在学习synchronized的时候,十分好奇当一个线程进入了一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法? 然后就做了个实验(实验代码最后贴出),最后得到了如下 ...