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

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

In Action

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

Total Submission(s): 3869    Accepted Submission(s): 1237

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
 

 

Author
Lost@HDU
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:            
 

 

1 //187MS    616K    1856 B    C++ 2 /* 3  4     题意: 5         题意挺重要的。一个源点0,源点每到一个站可得到一个pow[i],求得到总pow值一半以上时最短行走距离。 6          7     最短路+01背包: 8         首先最短路求出源点0到每一个点的距离,然后得出n个点,每个点有一个距离花费d,和一个价值权值w, 9     以到所有的点最短路程和作为背包容量,距离作为花费,权值作为价值,01背包。10     当dp[j]>sum_pow/2+1时的距离和j为所求。  11 12 */13 #include
14 #include
15 #include
16 #define N 10517 #define inf 0x7ffffff18 using namespace std;19 typedef struct node{20 int d,w;21 }node;22 node p[N];23 int vis[N];24 int d[N];25 int dp[N*N];26 vector
V[N];27 int n;28 int Max(int x,int y)29 {30 return x>y?x:y;31 }32 void spfa(int s)33 {34 for(int i=0;i<=n;i++)35 d[i]=inf;36 d[s]=0;37 vis[s]=1;38 queue
Q;39 Q.push(s);40 while(!Q.empty()){41 int u=Q.front();42 Q.pop();43 vis[u]=0;44 int m=V[u].size();45 for(int i=0;i
d[u]+w){49 d[v]=d[u]+w;50 if(!vis[v]){51 vis[v]=1;52 Q.push(v);53 }54 } 55 }56 }57 } 58 int main(void)59 {60 int t,m;61 int u,v,w,pow;62 scanf("%d",&t);63 while(t--)64 {65 int sd=0,sw=0;66 scanf("%d%d",&n,&m);67 for(int i=0;i<=n;i++) V[i].clear();68 for(int i=0;i
=p[i].d;j--)88 dp[j]=Max(dp[j],dp[j-p[i].d]+p[i].w);89 int ans=0;90 for(int i=1;i<=sd;i++)91 if(dp[i]>=sw/2+1){ 92 ans=i;break;93 }94 if(ans==0) puts("impossible");95 else printf("%d\n",ans);96 }97 return 0;98 }

 

 

转载于:https://www.cnblogs.com/GO-NO-1/p/3745394.html

你可能感兴趣的文章
Nexus杂
查看>>
Android --- GreenDao的实现(ORM框架)
查看>>
Linux平台Java调用so库-JNI使用例子
查看>>
Spring Data JPA
查看>>
项目管理修炼之道之规划项目
查看>>
Web服务器压力测试工具http_load、webbench、ab、Siege使用教程
查看>>
RHEL6.3 源码安装Puppet
查看>>
Mac软件下载备忘
查看>>
java 泛型初探
查看>>
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory
查看>>
就是一个表格
查看>>
CakePHP 2.x CookBook 中文版 第三章 入门 之 CakePHP 的结构
查看>>
Objective-C的算术表达式 .
查看>>
找回使用Eclipse删除的文件
查看>>
rabbitmq 消息系统 消息队列
查看>>
集成spring3、hibernate4、junit
查看>>
URL与ASCII
查看>>
Redis.conf 说明
查看>>
我的友情链接
查看>>
java读取properties配置文件
查看>>