LightOJ1079 Just another Robbery(DP)
题目大概是抢劫银行,每家银行都有一个收益和一个被抓的概率,求在被抓概率小于P的条件下能获得的最大收益。
- dp[i][j]表示抢劫前i家银行收益为j被抓的最小概率
- dp[0][0]=0
- dp[i][j]=min(dp[i-1][j],dp[i-1][j-m[i]]+(1-dp[i-1][j-m[i]])*p[i])
最后遍历一遍找答案就是了。
#include<cstdio>
#include<algorithm>
using namespace std;
double d[][];
int main(){
int t,n,x[];
double p,y[];
scanf("%d",&t);
for(int cse=; cse<=t; ++cse){
scanf("%lf%d",&p,&n);
int sum=;
for(int i=; i<=n; ++i){
scanf("%d%lf",x+i,y+i);
sum+=x[i];
}
for(int i=; i<=n; ++i){
for(int j=; j<=sum; ++j) d[i][j]=;
}
d[][]=;
for(int i=; i<=n; ++i){
for(int j=; j<=sum; ++j){
if(j>=x[i]) d[i][j]=min(d[i-][j],d[i-][j-x[i]]+(-d[i-][j-x[i]])*y[i]);
else d[i][j]=d[i-][j];
}
}
for(int i=sum; i>=; --i){
if(d[n][i]<p){
printf("Case %d: %d\n",cse,i);
break;
}
}
}
return ;
}
LightOJ1079 Just another Robbery(DP)的更多相关文章
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)
Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...
- 最长公共子序列长度(dp)
/// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...
随机推荐
- [codeforces 260]B. Ancient Prophesy
[codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain th ...
- Java数据库ResultSet转json实现
现在有很多json相关的Java工具,如json-lib.gson等,它们可以直接把JavaBean转换成json格式. 在开发中,可能会从数据库中获取数据,希望直接转成json数组,中间不通过bea ...
- HDU1711
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Java单链表、双端链表、有序链表实现
单链表: insertFirst:在表头插入一个新的链接点,时间复杂度为O(1) deleteFirst:删除表头的链接点,时间复杂度为O(1) 有了这两个方法,就可以用单链表来实现一个栈了,见htt ...
- HDFS 原理、架构与特性介绍--转载
原文地址:http://www.uml.org.cn/sjjm/201309044.asp 本文主要讲述 HDFS原理-架构.副本机制.HDFS负载均衡.机架感知.健壮性.文件删除恢复机制 1:当前H ...
- 部署Office Web Apps Server并配置其与SharePoint 2013的集成
部署Office Web Apps Server并配置其与SharePoint 2013的集成 Office Web Apps Server 是新的 Office 服务器产品,它提供 Word.P ...
- php中GD库的简单使用
在php中需要图像处理的地方GD库会发挥重要的作用,php可以创建并处理包括GIF,PNG,JPEG,WBMP以及XPM在内的多种图像格式,简单的举几个例子: 1.用GD库会创建一块空白图片,然后绘制 ...
- CodeForces - 417A(思维题)
Elimination Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- java操作AJAX
1,get方式的AJAX function sendAjaxReq() { //1,创建ajax引擎 XMLHttpRequest对象 var req = new XMLHttpRequest() | ...
- MFC 文件按行读写 CStdioFile
//写文件 CStdioFile file; file.Open("test.txt",CFile::modeCreate|CFile::modeReadWrite); file. ...