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. 无桌面的linux 安装VMWare Tools

    1.在vmware虚拟机选项下,选择安装vmware-tools 2.将vmware安装目录下的linux.iso装载到系统中 2.1.选择需安装VMWareTools的虚拟机,右击--可移动设备-- ...

  2. 【PL/SQL】匿名块、存储过程、函数、触发器

    名词解释 子程序:PL/SQL的过程和函数统称为子程序. 匿名块:以DECLARE或BEGIN开始,每次提交都被编译.匿名块因为没有名称,所以不能在数据库中存储并且不能直接从其他PL/SQL块中调用. ...

  3. 【Oracle】恢复重做日志组

    我们在Oracle的日常运维中,有可能会遇到重做日志组丢失的情况.下面我将模拟丢失不同状态的日志组,并分别给出解决办法: 重做日志有以下几种状态,如下: -  CURRENT:此状态表示正在被 LGW ...

  4. 设计包含min()函数的栈

    题目:定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素.要求函数min.push以及pop的时间复杂度都是O(1). 分析:这是去年google的一道面试题. 我看到这道题目时,第一反应 ...

  5. 图像连通域检测的2路算法Code

    本文算法描述参考链接:http://blog.csdn.net/icvpr/article/details/10259577 两遍扫描法: (1)第一次扫描: 访问当前像素B(x,y),如果B(x,y ...

  6. 【sqli-labs】 less25 GET- Error based -All you OR&AND belong to us -string single quote(GET型基于错误的去除了or和and的单引号注入)

    加单引号 order by一下 http://localhost/sqli-labs-master/Less-25/?id=1' order by 1%23 order by 变成了der by 下面 ...

  7. day008 字符编码之 字符编码 、Python2和Python3字符编码的区别

    计算机基础(掌握) 启动应用程序的流程 双击qq 操作系统接受指令然后把该操作转化为0和1发送给CPU CPU接受指令然后把指令发送给内存 内存接受指令把指令发送给硬盘获取数据 qq在内存中运行 文本 ...

  8. SDWC2017游记

    果然我还是那么弱啊.——$Mingqi_H.$ Day -1 下午五点半回家.然而并没有什么事情可做.依旧是下载$Magical\,Mirai$,找一个黄油存起来. emmm...本来是打算去开发区那 ...

  9. linux vi面板如何复制一行

    linux vi面板如何复制一行 1)把光标移动到要复制的行上 2)按yy 3)把光标移动到要复制的位置 4)按p

  10. python爬虫03:那个叫做 Urllib 的库让我们的 python 假装是浏览器

    相信你已经摸清了 浏览器各种请求的套路 也知道了怎么在手机上进行请求和返回数据的抓取 那么接下来我们就开始来使用 python 了 代码 lu 起来 那么 怎么用 python 写各种请求呢? 今天要 ...