HDU 3339 最短路+01背包】的更多相关文章

In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5220    Accepted Submission(s): 1745 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project t…
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5951    Accepted Submission(s): 1998 Problem Description Since 1945, when the firs…
 Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across the globe. Nowadays,the crazy boy in FZU named AekdyCoin possesses some nuclear weapons and wanna destroy…
题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 问题描述 Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across th…
In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5472    Accepted Submission(s): 1843 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project t…
In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4764    Accepted Submission(s): 1569 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project t…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 60469    Accepted Submission(s): 25209 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bo…
饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28562    Accepted Submission(s): 9876 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …  The bone collect…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=585&pid=1003 题解: 由于数据比较小,所以可以转化为判定性问题,即: dp[i][j][kk]表示走到i,j这一点时吃了kk重的蛋糕,转移方程只要考虑这一点的蛋糕吃和不吃两种情况(01背包) 代码: #include<iostr…
hdu 1574 RP问题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1574 分析:01背包的变形. RP可能为负,所以这里分两种情况处理一下就好. 初始化要注意. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define inf 0x3f3f3f3f int…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路:需要首先处理一下的的01背包,当饭卡余额大于等于5时,是什么都能买的,所以题目要饭卡余额最小,那预留5元(相当于饭卡余额为5)来买最贵的菜 然后对剩下n-1进行01背包dp才是正确的.但是还存在一个问题,那就饭卡初始余额小于5时,也要处理掉. 下面讲01背包(原型可以看大牛的背包九讲,本人也正在学习),定义dp[i][j]为买前i种菜品剩下j元时的最大消费值等于下面两中情况之一的值 有两种来…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 57334    Accepted Submission(s): 23933 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bon…
这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include <cstdio> using namespace std; #define N 1007 int c[N],w[N],dp[N]; int main() { int t,i,n,V,v; scanf("%d",&t); while(t--) { scanf("%d%…
这道题有个小小的坎,就是低于5块不能选,大于5块,可以任意选,所以就在初始条件判断一下剩余钱数,然后如果大于5的话,这时候就要用到贪心的思想,只要大于等于5,先找最大的那个,然后剩下的再去用背包去选择,这样的结果一定是最优的.因为最大的那个一定会被选中,剩下多少钱都无所谓,用背包可以获得剩下的最优解,所以最后也是最优解 代码如下 #include <cstdio> #include <cstring> #include <algorithm> using namespa…
先将前n-1个从小到大排序.对m-5进行01背包.然后答案就是m-dp[m-5]-a[n-1] 至于为什么最后减去最贵的菜品,而不是把最贵的菜品也放到01背包里呢, 由于假设能够把最贵菜品a[n-1]能够放到背包里.那么其它菜品a[i]也一定能够放在背包里(背包的容量为m-5),最后都是减去a[i]+a[n-1],所以能够吧最贵的菜品不放入背包,直接最后减去 #include<iostream> #include<stdio.h> #include<algorithm>…
题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream>…
Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 1978    Accepted Submission(s): 792 Problem Description Recently, iSea went to an ancient country. For such a long time, it was…
题意: 有 n 个团队和 m 艘船,每艘船的载客量为 k,每个团队的人数为ai+1 ,转载该团队可获利润 bi,要求每个团队的所有人必须在同一艘船上, 且团队优先级高的团队所在船编号不能大于优先级低的团队,求可以获得的最大利润. 题解:其实没什么,只需要01背包就可以了,只不过优先考虑团队优先级高的.分析:dp[i] 表示获得 i 利润时需要的最少船位,且要保证优先级高的团队优先考虑. #include<cstdio> #include<cmath> #include<ios…
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下,计算出所能抢劫得到的最多资金. 思路:一开始把被抓概率当做背包容量来做,结果错了,很重要的一点就是逃脱概率的计算,不是简单的相加相减,而是在上一家银行抢劫时的逃脱概率再乘以这一次的逃脱概率. 举个例子: 三家银行的被抓概率为P1,P2,P3.那么去抢劫这三家银行的逃脱概率为(1-P1)*(1-P2)…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 29618    Accepted Submission(s): 10834 Problem Description The aspiring Roy the Robb…
Hot~~招聘——巴卡斯(杭州),壹晨仟阳(杭州),英雄互娱(杭州) (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队? Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18808    Accepted Submission(s): 6941 Problem Description The aspi…
题目:题目链接 思路:不难看出,合成每个宝石需要消耗一定的魔力值,每个宝石有一定的收益,所以只要我们知道每个宝石合成的最小花费,该题就可以转化为一个背包容量为初始魔力值的完全背包问题,每个宝石的最小花费可以用dijkstra跑一遍最短路算出,路径长度用合成花费表示. AC代码: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <…
In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4859    Accepted Submission(s): 1600 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57986    Accepted Submission(s): 19484   Problem Description Nowadays, we all know that Computer College is the biggest departme…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; typedef pair<int,int> PII; #define PB…
题意: 小A要去抢劫银行,但是抢银行是有风险的,因此给出一个float值P,当被抓的概率<=p,他妈妈才让他去冒险. 给出一个n,接下来n行,分别给出一个Mj和Pj,表示第j个银行所拥有的钱,以及抢劫该银行被抓的可能性. 注意:抢劫各个银行被抓的可能是独立事件! 思路: 由于被抓的可能性float型,而且不仅仅只有两位,float型精度一般小数点后6-7位, 假若将被捕可能性看做容量,开10^6的数组,WA:开10^7的数组,MLE. 因此若从一般的角度,即将被捕可能性转化成整数,看做容量,将抢…
很标准的01背包问题 //#define LOCAL #include <algorithm> #include <cstdio> #include <cstring> using namespace std; + ; int w[maxn], v[maxn], dp[maxn]; int main(void) { #ifdef LOCAL freopen("2602in.txt", "r", stdin); #endif int…
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across the globe. Nowadays,th…
解题思路:给出一个临界概率,在不超过这个概率的条件下,小偷最多能够偷到多少钱.因为对于每一个银行都只有偷与不偷两种选择,所以是01背包问题. 这里有一个小的转化,即为f[v]代表包内的钱数为v的时候,小偷不被逮捕的概率,这样我们在用 for(i=1;i<=n;i++) { for(v=vol;v>=0;v--) f[v]=max(f[v],f[v-c[i]]*(1-p[i]));} 的过程中,在求出最大的不被抓的概率过程中,记录下了在此过程中的包中的钱数与此时对应的概率,这样最后只需用一个循环…