Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize CF167B
来源:互联网 发布:淘宝店铺包邮怎么设置 编辑:程序博客网 时间:2024/05/22 03:43
考虑把得到的奖和获取的背包容量两个状态分开来算概率
结果再把符合要求的两个状态的概率相乘
#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <queue>#include <cstdio>#include <map>#include <set>#include <utility>#include <stack>#include <cstring>#include <cmath>#include <vector>#include <ctime>#include <bitset>using namespace std;#define pb push_back#define sd(n) scanf("%d",&n)#define sdd(n,m) scanf("%d%d",&n,&m)#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)#define sld(n) scanf("%lld",&n)#define sldd(n,m) scanf("%lld%lld",&n,&m)#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)#define sf(n) scanf("%lf",&n)#define sff(n,m) scanf("%lf%lf",&n,&m)#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)#define ss(str) scanf("%s",str)#define ans() printf("%d",ans)#define ansn() printf("%d\n",ans)#define anss() printf("%d ",ans)#define lans() printf("%lld",ans)#define lanss() printf("%lld ",ans)#define lansn() printf("%lld\n",ans)#define fansn() printf("%.10f\n",ans)#define r0(i,n) for(int i=0;i<(n);++i)#define r1(i,e) for(int i=1;i<=e;++i)#define rn(i,e) for(int i=e;i>=1;--i)#define rsz(i,v) for(int i=0;i<(int)v.size();++i)#define szz(x) ((int)x.size())#define mst(abc,bca) memset(abc,bca,sizeof abc)#define lowbit(a) (a&(-a))#define all(a) a.begin(),a.end()#define pii pair<int,int>#define pli pair<ll,int>#define pll pair<ll,ll>#define mp make_pair#define lrt rt<<1#define rrt rt<<1|1#define X first#define Y second#define PI (acos(-1.0))#define sqr(a) ((a)*(a))typedef long long ll;typedef unsigned long long ull;const ll mod = 1000000000+7;const double eps=1e-9;const int inf=0x3f3f3f3f;const ll infl = 10000000000000000;const int maxn= 200+10;const int maxm = 40000+10;//Pretests passedint in(int &ret){ char c; int sgn ; if(c=getchar(),c==EOF)return -1; while(c!='-'&&(c<'0'||c>'9'))c=getchar(); sgn = (c=='-')?-1:1; ret = (c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0'); ret *=sgn; return 1;}struct node{ int a,b,c; bool operator <(const node &o)const { if(a!=o.a)return a<o.a; if(b!=o.b)return b<o.b; return c<o.c; } bool operator == (const node &o)const { return a==o.a&&b==o.b&&c==o.c; }};int pro[maxn];int pr[maxn];bool dp1[maxn][maxn];//i j the ith - win jbool dp2[maxn][maxn][maxn];// i j k the ith - win j - had kint prizecnt;int bagcnt;double p1[maxn][maxn];//prizedouble p2[maxn][maxn][maxn];//bagint main(){#ifdef LOCAL freopen("input.txt","r",stdin);// freopen("output.txt","w",stdout);#endif // LOCAL int n,l,k; sddd(n,l,k); r1(i,n)sd(pro[i]); r1(i,n)sd(pr[i]); dp1[0][0]=1; p1[0][0]=1; dp2[0][0][k] = 1; p2[0][0][k] = 1; for(int i=1; i<=n; ++i) { if(pr[i]<0) { for(int j = 0; j<=prizecnt; ++j) { if(dp1[prizecnt][j]) { if(pro[i]==0)dp1[prizecnt+1][j] = 1, p1[prizecnt+1][j] += p1[prizecnt][j]; else if(pro[i]==100)dp1[prizecnt+1][j+1] = 1 , p1[prizecnt+1][j+1] += p1[prizecnt][j]; else { dp1[prizecnt+1][j+1] = dp1[prizecnt+1][j] = 1; p1[prizecnt+1][j] += p1[prizecnt][j]*(0.01*(100-pro[i])); p1[prizecnt+1][j+1] += p1[prizecnt][j]*(0.01*pro[i]); } } } prizecnt++; } else { for(int j = 0; j<=200; ++j) { for(int win = 0 ; win <= bagcnt; ++win) { if(dp2[bagcnt][win][j]) { int mx = min(200,j+pr[i]); if(pro[i]==0)dp2[bagcnt+1][win][j] = 1, p2[bagcnt+1][win][j] += p2[bagcnt][win][j]; else if(pro[i]==100)dp2[bagcnt+1][win+1][mx] = 1 , p2[bagcnt+1][win+1][mx] += p2[bagcnt][win][j]; else { dp2[bagcnt+1][win+1][mx] = dp2[bagcnt+1][win][j] = 1; p2[bagcnt+1][win][j] += p2[bagcnt][win][j]*(0.01*(100-pro[i])); p2[bagcnt+1][win+1][mx] += p2[bagcnt][win][j]*(0.01*pro[i]); } } } } bagcnt++; } } double ans = 0; for(int i=0; i<=prizecnt; ++i) { for(int j = 0; j<=bagcnt;++j) { if(i+j<l)continue; for(int bag = i; bag<=200; ++bag) ans+= p1[prizecnt][i]*p2[bagcnt][j][bag]; } } printf("%.10f",ans); return 0;}
阅读全文
0 0
- Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize CF167B
- Codeforces 167 B. Wizards and Huge Prize
- codeforces 167B Wizards and Huge Prize DP 概率
- Codeforces 167B Wizards and Huge Prize 概率dp(水
- Codeforces 167B Wizards and Huge Prize 概率dp
- codeforces 167B Wizards and Huge Prize 概率dp
- Codeforces 168D Wizards and Huge Prize
- codeforces 167B Wizards and Huge Prize (概率dp,类似背包)
- Codeforces 400 C. Inna and Huge Candy Matrix【 Codeforces Round #234 (Div. 2)】
- Codeforces Round #129 (Div. 1) B. Little Elephant and Cards
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
- Codeforces Round #228 (Div. 1)-B-Fox and Minimal path
- Codeforces Round #129 (Div. 1) B. Little Elephant and Cards
- Codeforces Round #243 (Div. 1) B Sereja and Table
- Codeforces Round #253 (Div. 1) B. Andrey and Problem
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array
- Codeforces Round #257 (Div. 2)1B Jzzhu and Sequences
- Codeforces Round #263 (Div.1) B. Appleman and Tree
- adb shell时,提示error: unknown host service的解决办法
- java迭代器
- 学习PHP时一定要注意这三点
- Andrew Ng's deeplearning Course1Week1 Practice Questions(练习题)
- cookie和session自我总结
- Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize CF167B
- 解决Maven update project之后版本问题
- 版本控制-简介
- Hadoop知识点
- Still unable to dial persistent://xxx:80 after 3 attempts
- 毫秒级别的时间差
- linux系统调用分析
- python钩子脚本
- java如何得到GET和POST请求URL和参数列表(转载)