HDU 4815 Little Tiger vs. Deep Monkey 背包问题
来源:互联网 发布:js如何给div赋id 编辑:程序博客网 时间:2024/05/22 23:01
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815
题意:很“内涵”的一个题面,题意是给出N道题,和一个概率P,然后给出每道题对应的得分aa[i](每道题只有两个选项,一个正确一个错误)。两个人来答题,一个人是随机选择答案,问另一个人至少要答多少分才能保证有P的概率不会失败。
思路:是一道DP题,最开始想强行枚举所有情况,找到需要分数,后来发现40道题强行枚举2^40必然超时,思路就中断了,后来想到DP,刚开始DP的可能得到的分数,但是很不靠谱,发现就是一个01背包问题啊,每道题可以选择放入背包或者不放入背包,对于每种得分记录对应的种类数。然后从小到大寻找可以满足条件,即情况总和对应概率大于P的得分。
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include<cstdlib>#include<queue>#include<stack>#include<vector>#include<ctype.h>#include<algorithm>#include<string>#define PI acos(-1.0)#define maxn 10005#define INF 0x7ffffffftypedef long long ll;using namespace std;long long vis[40005];long long dd[45];int init(){ dd[1]=2; for(int i=2; i<=40; i++) dd[i]=dd[i-1]*2;}int main(){ int tot; int T; scanf("%d",&T); init(); while(T--) { scanf("%d",&tot); double pos; memset(vis,0,sizeof(vis)); vis[0]=1; scanf("%lf",&pos); int aa[45]; int bb=0; for(int i=0; i<tot; i++) { scanf("%d",&aa[i]); bb+=aa[i]; } sort(aa,aa+tot); for(int i=0; i<tot; i++) { for(int j=bb; j>=aa[i]; j--) { vis[j]+=vis[j-aa[i]]; } } long long cc=0; for(int k=0; k<=bb; k++) { cc+=vis[k]; double ee=cc; double ff=dd[tot]; double rec=ee/ff; if(rec>=pos) { printf("%d\n",k); break; } } } return 0;}
1 0
- HDU 4815 Little Tiger vs. Deep Monkey 背包问题
- hdu 4815 Little Tiger vs. Deep Monkey (背包+思维)
- [hdu 4815]Little Tiger vs. Deep Monkey 01背包
- HDU 4815 Little Tiger vs. Deep Monkey 01背包
- -----hdu 4815 -01背包- Little Tiger vs. Deep Monkey
- HDU 4815 Little Tiger vs. Deep Monkey
- hdu 4815 Little Tiger vs. Deep Monkey
- hdu 4815 Little Tiger vs. Deep Monkey
- HDU - 4815 Little Tiger vs. Deep Monkey
- HDU 4815 Little Tiger vs. Deep Monkey
- Little Tiger vs. Deep Monkey HDU
- HDU 4815 Little Tiger vs. Deep Monkey (0/1背包应用)
- hdu 4815 Little Tiger vs. Deep Monkey 概率dp
- HDU 4815——Little Tiger vs. Deep Monkey
- hdu 4815 Little Tiger vs. Deep Monkey(数学+dp)
- 【HDU】4815 - Little Tiger vs. Deep Monkey(母函数)
- HDU 4815 Little Tiger vs. Deep Monkey(母函数)
- HDOJ 4815 Little Tiger vs. Deep Monkey
- ndkr8d编译x264-snapshot-20140213-2245
- CentOS 安装ftp服务器vsftpd记录
- hadoop 创建用户及hdfs权限,hdfs操作等常用shell命令
- FMDB 简单使用
- Linux 内核使用register_filesystem添加自定义文件系统deanfs
- HDU 4815 Little Tiger vs. Deep Monkey 背包问题
- C++ STL 中 map 容器的说明和使用技巧
- hdu 4858 项目管理(STL容器)
- HDU4283——You Are the One(区间DP)
- 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的有关问题
- 使用Flume Log4j Appender正确的姿势
- LaTeX新人教程,30分钟从完全陌生到基本入门
- poj 2533 动态规划 最长子序列
- c语言之————有头循环双链表(公用par)