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 ...
 
随机推荐
- [微信小程序]计算自己手机到指定位置的距离
			
目的: 根据目的地的坐标计算自己手机的位置离目的地的距离的 核心思路: 后续操作必须等所有异步请求都返回了才能继续 使用 const qqmap = require("../../utils ...
 - sklearn包学习
			
1首先是sklearn的官网:http://scikit-learn.org/stable/ 在官网网址上可以看到很多的demo,下边这张是一张非常有用的流程图,在这个流程图中,可以根据数据集的特征, ...
 - 【laravel5.6】laravel 自定义公共函数
			
1.在 app/Helpers/ 新建一个文件 functions.php,当然这个文件位置和名称你可以自己定义,创建一些函数用于全局调用: 2.在composer.json中的autoload下增加 ...
 - DOS 如何取当前时间做为文件名?
			
如果要取得以日期为文件名的文件,假设在命令行下键入date返回形式为:当前日期: 2005-06-02 星期四echo > %date:~0,4%%date:~5,2%%date:~8,2%~表 ...
 - vue比较模板来跟新数据
			
一,使用场景: 点击menu通过路由,跳转当前列表,第二次点击menu,希望可以刷新列表: 二,解决思路: 给路由添加时间戳: 三,参考观点: 用 :key管理可复用的元素 模板相同,会造成一种“复用 ...
 - 【BZOJ1814】Ural 1519 Formula 1 插头DP
			
[BZOJ1814]Ural 1519 Formula 1 题意:一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数.(n,m<=12) 题解:插头DP板子题,刷板 ...
 - vue--点击事件
			
<template> <div id="app"> <p>{{msg}}</p> <input type="text ...
 - Spark2 探索性数据统计分析
			
data数据源,请参考我的博客http://www.cnblogs.com/wwxbi/p/6063613.html import org.apache.Spark.sql.DataFrameStat ...
 - Spark2 Dataset之collect_set与collect_list
			
collect_set去除重复元素:collect_list不去除重复元素select gender, concat_ws(',', collect_set(children)), ...
 - numpy.argsort详解
			
numpy.argsort(a, axis=-1, kind='quicksort', order=None)[source] Returns the indices that would sort ...