hdu 4815 Little Tiger vs. Deep Monkey
来源:互联网 发布:用c语言模拟进程的创建 编辑:程序博客网 时间:2024/05/21 10:14
题意:n道判断题,每题有相应的分数,一个人瞎蒙,问另一个人需要得多少分才能达到p的概率不输给他。
思路:dp(类似01背包)。dp(i,j)表示回答到第i题,分数为j分有多少种回答方法。然后根据概率的定义计算。
#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <iomanip> #include <cstdlib> #include <string> #include <string.h> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <ctype.h> #include <sstream> #define INF 1000000000 #define ll long long #define min3(a,b,c) min(a,min(b,c))#define max3(a,b,c) max(a,max(b,c)) using namespace std;ll s[42];ll dp[2][40010];ll pre[40010];int main(){int t;cin>>t;while(t--){memset(dp,0,sizeof(dp));int n;double p;cin>>n>>p;for(int i=1;i<=n;i++){scanf("%I64d",&s[i]);}dp[0][0]=1;for(int i=1;i<=n;i++){for(int j=0;j<=40000;j++){dp[i%2][j]=dp[(i-1)%2][j];if(j-s[i]>=0){dp[i%2][j]+=dp[(i-1)%2][j-s[i]];}}}pre[0]=dp[n%2][0];for(int i=1;i<=40000;i++){pre[i]=pre[i-1]+dp[n%2][i];}int ans=-1;for(int i=0;i<=40000;i++){double test=(pre[i]+0.0)/(pre[40000]+0.0);if(test>p-0.000000001){ans=i;break;}}cout<<ans<<endl;}return 0;}
0 0
- 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 概率dp
- hdu 4815 Little Tiger vs. Deep Monkey (背包+思维)
- [hdu 4815]Little Tiger vs. Deep Monkey 01背包
- 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(数学+dp)
- 【HDU】4815 - Little Tiger vs. Deep Monkey(母函数)
- HDU 4815 Little Tiger vs. Deep Monkey(母函数)
- -----hdu 4815 -01背包- Little Tiger vs. Deep Monkey
- HDOJ 4815 Little Tiger vs. Deep Monkey
- Little Tiger vs. Deep Monkey
- DBUS基础知识
- 实验一: vc编程灵活应用的修改:类模板的多文件实现
- IT软件开发 工作一年随笔
- linux系统编程之文件io小结
- TRIZ系列-创新原理-20-有效作用的连续性原理
- hdu 4815 Little Tiger vs. Deep Monkey
- 面向对象程序设计上机练习六(类和对象)
- Linux环境下一些常见且有用的命令
- android学习二:创建一个AVD(安卓模拟器)
- 黑马程序员——集合类(list和set)(一)
- 智能指针(Smart Pointers)
- 编程之美---旋转字符串
- HDU 1203 I NEED A OFFER!(01背包)
- OpenCV Start