In Action

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

Total Submission(s): 4859    Accepted Submission(s): 1600
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:  1217 1385 1548 3338 1546 

n个电站,m条路,点0处出发,每一个电站都有一定的发电量p [ i ],也给出了m条路,a--b需要c的油,如果成功的控制一半以上的电量就视为胜利,现在求最少的耗油量,先用迪杰斯特拉处理路径,背包中存i升的油最多控制j的电量(dp[ i ] = j)然后找出最小的dp[ i ] > sum/2,输出i

ac代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define MAXN 110
int map[MAXN][MAXN],vis[MAXN],dis[MAXN],dp[11000],p[MAXN];
int n,m;
void disjtra()
{
memset(vis,0,sizeof(vis));
memset(dis,INF,sizeof(dis));
for(int i=0;i<=n;i++)
dis[i]=map[0][i];
vis[0]=1;
for(int i=1;i<=n;i++)
{
int minn=INF;
int flag=0;
for(int j=0;j<=n;j++)
{
if(!vis[j]&&minn>dis[j])
{
minn=dis[j];
flag=j;
}
}
vis[flag]=1;
for(int j=0;j<=n;j++)
{
if(!vis[j]&&dis[flag]+map[flag][j]<dis[j])
{
dis[j]=dis[flag]+map[flag][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;
disjtra();
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++)
{
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;
}

hdoj--3339--In Action(最短路+01背包)的更多相关文章

  1. HDU 3339 In Action 最短路+01背包

    题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  2. hdu3339In Action(最短路+01背包)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...

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

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

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

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

  5. HDOJ 3339 In Action

    最短路+01背包 In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. HDU-3339 IN ACTION(Dijkstra +01背包)

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

  7. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  8. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  9. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  10. In Action(最短路+01背包)

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 查看Oracle数据库表空间大小,是否需要增加表空间的数据文件

    在数据库管理中,磁盘空间不足是DBA都会遇到的问题,问题比较常见. --1查看表空间已经使用的百分比 Sql代码 select a.tablespace_name,a.bytes/1024/1024 ...

  2. 在命令提示符窗口下(cmd)使用指令操作并编译java代码,运行java编译代码

    使用cmd操作java代码,编译.java文件,运行.class文件. 操作步骤: 1:创建一个文件夹: 例如:在e盘根目录(\)下面创建一个名为Hello的文件夹: 使用md指令:如图 在e盘中会生 ...

  3. 【sqli-labs】 less25a GET- Blind based -All you OR&AND belong to us -Intiger based(GET型基于盲注的去除了or和and的整型注入)

    因为过滤是针对输入的字符串进行的过滤,所以如果过滤了or and的话,提交id=1和id=and1结果应该相同 http://localhost/sqli-labs-master/Less-25a/? ...

  4. 11.02 跳过表中n行

    select x.enamefrom (select a.ename,(select count(*)from emp bwhere b.ename <=a.ename) as rnfrom e ...

  5. 新浪某个tab 页模仿

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. Memcached 之增删改查命令

    memcache是高性能 ,分布式的内存对象缓存系统,非关系型数据库. 一.增 语法:add  key  flag  expire  length key:值的一个名字 flag:一个标志,是一个正整 ...

  7. openstack--memecache

    一.缓存系统 静态web页面: 1.工作流程: 在静态Web程序中,客户端使用Web浏览器(IE.FireFox等)经过网络(Network)连接到服务器上,使用HTTP协议发起一个请求(Reques ...

  8. eas之EAS手工打包及快速部署工具

    EAS手工打包及快速部署工具:jar包的命名是项目名就好了.   1. 在eas的工作空间下:E:\Easworkspace\Project_0 有classes和deployed_metas这两个文 ...

  9. 【深度学习框架】使用PyTorch进行数据处理

      在深度学习中,数据的处理对于神经网络的训练来说十分重要,良好的数据(包括图像.文本.语音等)处理不仅可以加速模型的训练,同时也直接关系到模型的效果.本文以处理图像数据为例,记录一些使用PyTorc ...

  10. 【剑指Offer】1、二维数组中的查找

      题目描述:   在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否 ...