博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3339(最短路+01背包)
阅读量:5367 次
发布时间:2019-06-15

本文共 3237 字,大约阅读时间需要 10 分钟。

In Action

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5135    Accepted Submission(s): 1710

Problem 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,the crazy boy in FZU named AekdyCoin possesses some nuclear weapons and wanna destroy our world. Fortunately, our mysterious spy-net has gotten his plan. Now, we need to stop it.
But the arduous task is obviously not easy. First of all, we know that the operating system of the nuclear weapon consists of some connected electric stations, which forms a huge and complex electric network. Every electric station has its power value. To start the nuclear weapon, it must cost half of the electric network's power. So first of all, we need to make more than half of the power diasbled. Our tanks are ready for our action in the base(ID is 0), and we must drive them on the road. As for a electric station, we control them if and only if our tanks stop there. 1 unit distance costs 1 unit oil. And we have enough tanks to use.
Now our commander wants to know the minimal oil cost in this action.
 

 

Input
The first line of the input contains a single integer T, specifying the number of testcase in the file.
For each case, first line is the integer n(1<= n<= 100), m(1<= m<= 10000), specifying the number of the stations(the IDs are 1,2,3...n), and the number of the roads between the station(bi-direction).
Then m lines follow, each line is interger st(0<= st<= n), ed(0<= ed<= n), dis(0<= dis<= 100), specifying the start point, end point, and the distance between.
Then n lines follow, each line is a interger pow(1<= pow<= 100), specifying the electric station's power by ID order.
 

 

Output
The minimal oil cost in this action.
If not exist print "impossible"(without quotes).
 

 

Sample Input
2 2 3 0 2 9 2 1 3 1 0 2 1 3 2 1 2 1 3 1 3
 

 

Sample Output
5 impossible
题意:一些坦克要占据一些能量据点,坦克从0点出发,总共有编号1-n n个能量据点,如果要摧毁敌方,必须要占领能量据点的能量值达到总能量的一半以上,现在知道m条路径,以及坦克在m条路上的油耗,然后知道每个能量据点的能量值,问摧毁敌方所需的最少油耗.
题解:最短路+01背包,将每个能量据点看成背包容量,油耗看成价值,然后进行01背包求解.我不知道为什么数组刚开始开小了会报tle..
#include 
#include
#include
#include
#include
#include
using namespace std;const int N = 105;const int INF = 99999999;int graph[N][N];int low[N];bool vis[N];int w[N]; ///第i座城市所拥有的能源int dp[N*N]; ///dp[i]代表控制i吨能源所耗费的最少油量 (= =)没想到用什么词,就用吨好了int n,m;int dijkstra(int s){ for(int i=1;i<=n;i++){ low[i] = graph[s][i]; vis[i] = false; } low[s] = 0; vis[s] = true; for(int i=1;i
low[j]&&!vis[j]){ Min = low[j]; s = j; } } vis[s] = true; for(int j=1;j<=n;j++){ if(low[j]>low[s]+graph[s][j]&&!vis[j]){ low[j] = low[s]+graph[s][j]; } } }}int main(){ int tcase; scanf("%d",&tcase); while(tcase--){ scanf("%d%d",&n,&m); for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ if(i==j) graph[i][j] = 0; else graph[i][j] = INF; } } for(int i=0;i
=w[i];v--){ dp[v] = min(dp[v],dp[v-w[i]]+low[i]); } } int sum1 = sum/2+1; ///控制能量超过一半 int Min = INF; for(int i=sum1;i<=sum;i++){ if(dp[i]

 

转载于:https://www.cnblogs.com/liyinggang/p/5503082.html

你可能感兴趣的文章
星期五的收获
查看>>
proxmox 去除订阅提示
查看>>
使用Html.EditorFor()为文本框加上maxlength,placeholder等属性
查看>>
[转]后缀数组求最长重复子串
查看>>
设计模式——外观模式详解
查看>>
MVC3 控件
查看>>
mysql (一)
查看>>
photoshop图层样式初识1
查看>>
【.NET】使用HtmlAgilityPack抓取网页数据
查看>>
typedef的使用
查看>>
基于位置的本地商铺个性化推荐
查看>>
职场上一个人情商高的十种表现
查看>>
【底层原理】深入理解Cache (下)
查看>>
Elasticsearch安装中文分词插件IK
查看>>
进阶4:常见函数-单行函数
查看>>
简述企业信息化与企业架构关系
查看>>
npoi List 泛型导出
查看>>
流程图怎么画?分享绘制流程图简单方法
查看>>
squid的处理request和reply的流程
查看>>
硬件_陀螺仪
查看>>