/**
题目:hdu6007 Mr. Panda and Crystal
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007
题意:魔法师有m能量,有n种宝石,有些宝石给定了用魔法变出它需要的能量,以及该宝石可以卖出的价钱。
有些宝石没有给出,给出k个方程,表示某些宝石可以通过另外一些宝石合成。
求魔法师最多可以卖出多少钱。 思路:
处理方程,最短路求出所有的宝石用能量变出的最小能量值。
然后完全背包。 */ #include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<cstring>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const int N = ;
const int inf = 0x3f3f3f3f; int cost[N], price[N];
struct node
{
int goal;
vector<P> v;
}eq[N];
int dp[];
int main()
{
int cas = , T, n, m, k;
cin>>T;
while(T--)
{
scanf("%d%d%d",&m,&n,&k);
int flag;
for(int i = ; i <= n; i++){
scanf("%d",&flag);
if(flag==){
cost[i] = -;
scanf("%d",&price[i]);
}else
{
scanf("%d%d",&cost[i],&price[i]);
}
}
int x, y;
for(int i = ; i <= k; i++) eq[i].v.clear();
for(int i = ; i <= k; i++){
scanf("%d%d",&x,&y);
eq[i].goal = x;
int u, vv;
for(int j = ; j <= y; j++){
scanf("%d%d",&u,&vv);
eq[i].v.push_back(P(u,vv));
}
}
while()
{
int flag = ;
for(int i = ; i <= k; i++){
int sign = ;
int sum = ;
for(int j = ; j < (int)(eq[i].v.size()); j++){
P p = eq[i].v[j];
if(cost[p.first]==-){
sign = ; break;
}else
{
sum += cost[p.first]*p.second;
if(sum>m){///完全背包,最多m容量,所以超过m的能量花费,都不会被使用。这样避免溢出。
sum = m+; break;
}
}
}
if(sign){
if(cost[eq[i].goal]!=-){
if(cost[eq[i].goal]>sum){
cost[eq[i].goal] = sum;
flag = ;
}
}else
{
cost[eq[i].goal] = sum;
flag = ;
}
}
}
if(flag) break;
}
memset(dp, , sizeof dp);
for(int i = ; i <= n; i++){
if(cost[i]==-) continue;
for(int j = cost[i]; j <= m; j++){
dp[j] = max(dp[j],dp[j-cost[i]]+price[i]);
}
}
printf("Case #%d: %d\n",cas++,dp[m]);
}
return ;
}

hdu6007 Mr. Panda and Crystal 最短路+完全背包的更多相关文章

  1. Mr. Panda and Crystal(最短路+完全背包)

    http://codeforces.com/gym/101206/attachments 题意: T组输入,每组给出m,n,k,m为能量总数,n为水晶种类数,k为合成方案数.有的水晶可以用能量制造,有 ...

  2. Mr. Panda and Crystal HDU - 6007 最短路+完全背包

    题目:题目链接 思路:不难看出,合成每个宝石需要消耗一定的魔力值,每个宝石有一定的收益,所以只要我们知道每个宝石合成的最小花费,该题就可以转化为一个背包容量为初始魔力值的完全背包问题,每个宝石的最小花 ...

  3. HDU 6007 Mr. Panda and Crystal (背包+spfa)

    题意:你生活在一个魔法大陆上,你有n 魔力, 这个大陆上有m 种魔法水晶,还有n 种合成水晶的方式,每种水晶价格告诉你,并且告诉你哪些水晶你能直接造出来,哪些你必须合成才能造出来,问你n魔力最多能卖多 ...

  4. 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理

    2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...

  5. H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)

    Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday. It is k ...

  6. HDU 3339 In Action【最短路+01背包】

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Other ...

  7. HDU 3339 In Action【最短路+01背包模板/主要是建模看谁是容量、价值】

     Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the n ...

  8. Gym101194J Mr.Panda and TubeMaster 二分图、费用流

    传送门 看到这张图,是一个网格图,而且有回路限制,不难想到黑白染色. 一般来说我们对一张图黑白染色之后都是黑色点向白色点连边,但是这道题往这边想似乎就想不出建图方法了,因为"一个格子强制流满 ...

  9. Gym 101194C / UVALive 7899 - Mr. Panda and Strips - [set][2016 EC-Final Problem C]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

随机推荐

  1. 003java面试笔记——【java基础篇】从团八百失败面试总结的java面试题(未完待续)

    8.java 线程     1)线程概念,线程与进程      线程:线程是“进程”中某个单一顺序的控制流.也被称为轻量进程.线程是进程中的实体,一个进程可以拥有多个线程,一个线程必须有一个父进程.线 ...

  2. M.U.G.E.N Error怎么办

    当运行乱舞格斗2008的时候出现以下错误. 在任务管理器中找到M.U.G.E.N.exe这个进程,右击设置相关性,然后取消勾选其中一个,点击确定. 不要关闭这个窗口,否则M.U.G.E.N这个进程也将 ...

  3. PHPMailer_v5.1 使用[转]

    <?php /* * email 报警,主要检查服务器数据库是否还能正常连接 */ require("../common/config.php"); include(&quo ...

  4. java中Runtime类

    一.概述      Runtime类封装了运行时的环境.每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接.      一般不能实例化一个Runtime对象, ...

  5. python中,== 与 is 之间区别

    在python中,== 与 is 之间既有区别,又有联系,本文将通过实际代码的演示,力争能够帮助读到这篇文章的朋友以最短的时间理清二者的关系,并深刻理解它们在内存中的实现机制. 扯淡的话不多说,下面马 ...

  6. qs.stringify() 和JSON.stringify()的区别

    var a = {name:'hehe',age:10}; qs.stringify(a) // 'name=hehe&age=10' JSON.stringify(a) // '{" ...

  7. JDBC2.0操作:结果集,更新,插入,删除,批处理语句

    JDBC对ResultSet的支持 JDBC最重要的概念是批处理,可以一次完成多个语句的执行. 可滚动的结果集. 如果想创建可滚动的结果集,则在创建PrepareStatement时候必须指定创建的类 ...

  8. Linux管道符

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFpanVucGVuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  9. wcf json asp.net json

    function BindNewsTypeTree() { var parentid; // $.getJSON(serviceUrl + "NewsTypeService.svc/GetN ...

  10. 安装应用程序 报“ 997 重叠 I/O 操作在进行中”错解决办法

    解决办法: 原因: Per Microsoft's blog, patch KB2918614 appears to have caused installation issues 按照微软的博客,补 ...