题目来源: http://www.codechef.com/AUG13/problems/SHIRO

题目描述:

Shiro is leading an army to save the princess of his kingdom "Abra". The princess has been made a prisoner by the neighboring kingdom "Kadabra". Kadabra is a magical land and is full of challenges. Shiro's army has to passN levels before they can get to the princess. After each level, the army gets a few flags to carry along. The flags can either all be of kindom Abra OR all of kingdom Kadabra. The magic of Kadabra forces Shiro's army to carry the flags irrespective of which kingdom they belong to. The princess doesn't know Shiro or anyone from his army. She will not escape with them unless she can trust them. She will trust them only if the number of Abra's flags they are carrying is atleast as much as the number of Kadabra's flags.

The army gets ai flags at the end of the ith level. Probability that flags received at the end of the ith level will be Abra's flags ispi. Your task is to tell Shiro what is the probability that the princess will trust him once they reach her.

Input:

First line of input contains a single integer T, the number of test cases.

Each test starts with a single line having an integer, N, the number of levels in Kadabra.

Next line contains contains N integers with the ith integer beingai as described above.

Next line contains contains N integers with the ith integer beingpi as described above. Note that the probabilities given will be in percents.

Output:

For each test case, output a line containing the required probability. The answer will be accepted if the relative error is not more than 10-6.

Constraints:

1 ≤ T ≤ 100
1 ≤ N ≤ 100
1 ≤ ai ≤ 100
0 ≤ pi ≤ 100

Example:

Input:

2
5
1 2 3 4 4
0 100 100 0 50
2
5 5
50 60

Output:

0.5000000
0.8000000

题目大概意思:求Abra旗帜的个数大于等于总旗帜一半的概率,如第二组数据,一共有0,5,10,三种可能性,则p=0.5*0.6+0.5*0.4+0.5*0.6=0.8;

所以可以有一个递归式 Pro[j]=Pro[j]*(1-p[i])+Pro[j-a[i]]*p[i]   也就是DP。

最后求Pro[sum/2]~Pro[sum]的和

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#define MAX 10010
using namespace std;
double Pro[MAX];
int a[110];
double p[110];
int N;
int sum=0;
void input()
{scanf("%d",&N);for(int i=1;i<=N;i++){scanf("%d",&a[i]);sum+=a[i];}for(int i=1;i<=N;i++){int c;scanf("%d",&c);p[i]=(double)c/100;}
}
void solve()
{for(int i=1;i<=N;i++){for(int j=MAX;j>=a[i];j--){Pro[j]=Pro[j]*(1-p[i])+Pro[j-a[i]]*p[i];}for(int k=0;k<a[i];k++)Pro[k]=Pro[k]*(1-p[i]);}
}
int main()
{int T;scanf("%d",&T);while(T--){memset(Pro,0,sizeof(Pro));Pro[0]=1;input();solve();double ans=0;for(int i=((sum+1)/2);i<=sum;i++){//printf("%.5f\n",Pro[i]);ans+=Pro[i];}printf("%.7f\n",ans);sum=0;}
}

AGU13-Save The Princess相关推荐

  1. 基于cocos-2dx的游戏制作——I wanna save the princess

    在进行了两周的cocos学习之后,可以开始进行游戏的创作了. I wanna主要复杂的地方在于地图的设计以及逻辑实现.下面依次进行介绍.(使用c++) 一. 瓦片地图--tile map 1. 地图整 ...

  2. hdu1027 Ignatius and the Princess II (全排列 amp; STL中的神器)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1027 Ignatiu ...

  3. SDUTRescue The Princess(数学问题)

    题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To re ...

  4. 杭电1027Ignatius and the Princess II模拟

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1027 题目: Problem Description Now our hero finds the doo ...

  5. SDUT 2603:Rescue The Princess

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  6. The Magic Tower

    The Magic Tower Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. 强化学习q学习求最值_通过Q学习更深入地学习强化学习

    强化学习q学习求最值 by Thomas Simonini 通过托马斯·西蒙尼(Thomas Simonini) 通过Q学习更深入地学习强化学习 (Diving deeper into Reinfor ...

  8. 你需要知道的基础算法知识——STL和基础数据结构(八)

    引言 STL是C++的标准模板库,竞赛中很多常用的数据结构.算法在STL中都有,熟练地掌握它们在很多题目中能极大地简化编程. STL包括容器(container).迭代器(iterator).空间配置 ...

  9. UVA11764 Jumping Mario【Ad Hoc】

    Mario is in the final castle. He now needs to jump over few walls and then enter the Koopa's Chamber ...

  10. 苹果系统使用svg 动画_为什么要使用SVG图像:如何为SVG设置动画并使其快速闪电化

    苹果系统使用svg 动画 我们为什么要使用SVG? (Why Are We Using SVG?) The web development sector is growing at a rapid p ...

最新文章

  1. hdu2363 枚举最短路
  2. 如何完全卸载VS2010
  3. 视口和窗口的理解方法
  4. 数据库集群 MySQL主从复制
  5. 生成0到1之间随机数的C代码
  6. pat 乙级 1014 福尔摩斯的约会 (C++)
  7. python爬虫爬汽车图片_Python快速爬取车标网图片,以后不要说这什么车你不认识了!...
  8. 利用perspective 和 transform 里面的几个参数来实现旋转照片墙
  9. 这几个公众号隐藏着暴富的秘诀
  10. mysql命中索引规律
  11. LeetCode:二进制求和【67】
  12. 第三章:3.4 处理登陆的请求
  13. 广联达登录显示服务器异常去回答,广联达设置服务器异常5
  14. 两个实际任务掌握图像分类【Keras】(转)
  15. 华为 EC169 3G上网卡在MacPro中的使用
  16. npm init @vitejs/app 到底干了什么
  17. 易语言linux支持多线程,详解易语言启动多线程
  18. 金蝶K3系统如何更改已使用物料的计量单位信息
  19. MATLAB 绘制空间分布图,颜色代表数值(替代ArcGIS)
  20. Nginx+obs直播服务器,推流连接失败

热门文章

  1. 二值图像快速细化算法
  2. inflate()方法详解和源码分析
  3. Cosy主题3.0使用教程
  4. 小码哥学习感想第一天
  5. RationalDMIS 2020 手动特征测量注意事项
  6. ios error90096 错误
  7. 猎头猎取人才会注重人才的哪些点?
  8. Windows AppLocker被绕过:攻击者可不提权联网注入DLL
  9. 学计算机段子,段子手要失业了,计算机也懂幽默
  10. c语言有理数字符形式,C语言设计实现抽象数据类型有理数基本操作包括有理数的加法,减法,乘法,除法,以及求有理数的分子,分...