hdu3339In Action(最短路+01背包)
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
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
If not exist print "impossible"(without quotes).
Sample Input
2 3
0 2 9
2 1 3
1 0 2
1
3
2 1
2 1 3
1
3
Sample Output
impossible
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#define N 1000001
using namespace std;
int n,m;
int map[][];
int v[];
int dp[];
void Floy()//计算出0到各个发电站的最短距离,因为最多100个点,所以用floy
{
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(map[i][j]>map[i][k]+map[k][j])
{
map[i][j]=map[i][k]+map[k][j];
}
}
}
}
}
int main()
{
int T,zz,xx,yy,flag;
scanf("%d",&T);
while(T--)
{
flag=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
map[i][j]=N;
map[j][i]=N;
}
map[i][i]=;
}
for(int i=;i<m;i++)
{
scanf("%d%d%d",&xx,&yy,&zz);
if(map[xx][yy]>zz)//有重边
{
map[xx][yy]=zz;
map[yy][xx]=zz;
}
}
Floy();
int sum=,sum1=;
for(int i=;i<=n;i++)
{
scanf("%d",&v[i]);
sum1+=v[i];//计算出发电场的总能量。
if(map[][i]!=N)//计算出所有可行点的距离。
sum+=map[][i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)//以总距离为背包容量,发电站的能量为利润。
{
for(int j=sum;j>=map[][i];j--)
{
if(dp[j-map[][i]]+v[i]>dp[j])
{
dp[j]=dp[j-map[][i]]+v[i];
}
}
}
for(int i=;i<=sum;i++)
{
if(dp[i]>sum1/2.0)//必须炸掉一半多才可以阻止战争
{
flag=;
printf("%d\n",i);
break;
}
}
if(flag==) printf("impossible\n"); }
return ;
}
hdu3339In Action(最短路+01背包)的更多相关文章
- HDU 3339 In Action 最短路+01背包
题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3339 In Action【最短路+01背包】
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Other ...
- HDU 3339 In Action【最短路+01背包模板/主要是建模看谁是容量、价值】
Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the n ...
- HDU-3339 IN ACTION(Dijkstra +01背包)
Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the ...
- In Action(最短路+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- *HDU3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdoj--3339--In Action(最短路+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 3339 In Action (最短路径+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- 【转载】经典.net面试题目【为了笔试。。。。。】
. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成员 ...
- 【面试题】新东方.NET工程师面试题总结
1.学校几本(是否统招).英语等级.大学成绩排名Top%几.当前月薪(入职前是否能提供薪资证明材料).期望月薪 二本,统招英语四级排名top10 2.做过的项目技术栈是什么?(例如 .NET.Sql ...
- Python汉字转换成拼音
最近在使用Python做项目时,需要将汉字转化成对应的拼音. 网上的一些包大多是python2.x的,使用下面这个包,支持python3.6 xpinyin 0.5.5 >>> fr ...
- Android 编译时:m、mm、mmm、mma、mmma的区别
m:编译整个安卓系统 makes from the top of the tree mm:编译当前目录下的模块,当前目录下需要有Android.mk这个makefile文件,否则就往上找最近的Andr ...
- MyBatis学习之SpringMvc和MyBatis整合
1. 整合流程 Dao层: 1. SqlMapConfig.xml,空文件即可,需要文件头. 2. applicationContext-dao.xml. a) 数据库连接池 b) SqlSessio ...
- javaagent
-javaagent:<jarpath>[=<options>]load Java programming language agent, see java.lang.inst ...
- vim自定义语法高亮(syntax highlight)设置流程
这里用一个非常简单的例子来展示vim自定义自己的语法并高亮显示的设置流程. 所使用的实例语言是python,为了区分vim自带的python语法,我们把文件名保存为test.me,其内容如下图所示: ...
- msyql DATETIME类型和Timestamp之间的转换
DATETIME -> Timestamp: UNIX_TIMESTAMP(...) Timestamp -> DATETIME: FROM_UNIXTIME(...) select da ...
- pandas常用
#python中的pandas库主要有DataFrame和Series类(面向对象的的语言更愿意叫类) DataFrame也就是#数据框(主要是借鉴R里面的data.frame),Series也就是序 ...
- Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(转)
通过前面的学习,你可能大致了解了Quartz,本篇博文为你打开学习SSMM+Quartz的旅程!欢迎上车,开始美好的旅程! 本篇是在SSM框架基础上进行的. 参考文章: 1.Quartz学习——Qua ...