In Action
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4757 Accepted Submission(s): 1567
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.
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).
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 ,在总站0处有任意多的坦克,当且仅当一个坦克停在一个核电站处,这个核电站将会被关闭。但坦克每走一米要消耗一升油,问最少消耗多少升油。//思路:先求出总站0到每个核电站的最短距离。然后用01背包求出最少消耗的油量。具体看代码。#include<stdio.h> #include<string.h> #include<algorithm> #define INF 0x3f3f3f3f using namespace std; int map[110][110]; int p[110]; int dis[110]; int vis[110]; int dp[11000]; int n,m; void dijks()//求出最短路 { int i,j,k,min; memset(vis,0,sizeof(vis)); for(i=0;i<=n;i++) dis[i]=map[0][i]; vis[0]=1; for(i=1;i<=n;i++) { min=INF; k=0; for(j=0;j<=n;j++) { if(!vis[j]&&min>dis[j]) { min=dis[j]; k=j; } } vis[k]=1; for(j=0;j<=n;j++) { if(!vis[j]&&dis[k]+map[k][j]<dis[j]) dis[j]=dis[k]+map[k][j]; } } } int main() { int t,i,j; int a,b,c; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(map,INF,sizeof(map)); while(m--) { scanf("%d%d%d",&a,&b,&c); if(c<map[a][b]) map[a][b]=map[b][a]=c; } int sum=0; for(i=1;i<=n;i++)//求出核电站网的总的能量 { scanf("%d",&p[i]); sum+=p[i]; } sum/=2;//关掉其中能量值一半以上的核电站即可 dijks(); int v=0; for(i=1;i<=n;i++)//关掉所有核电站的燃油量。(背包的总容积) { if(dis[i]!=INF) v+=dis[i]; } memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++)//01背包 { if(dis[i]!=INF) { for(j=v;j>=dis[i];j--) dp[j]=max(dp[j],dp[j-dis[i]]+p[i]); } } int flag=1; for(i=0;i<=v;i++)//找出关掉的核电站的能量值大于目标值(总能量的一半以上) { if(dp[i]>sum) { flag=0; break; } } if(flag) printf("impossible\n"); else printf("%d\n",i); } return 0; }