博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3339 In Action 背包+flyod
阅读量:7109 次
发布时间:2019-06-28

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

In Action

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=3339

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

HINT

 

题意

给你一个图,每个图都有权值,然后让你派出多辆坦克,破环至少占权值一半的城市,派出坦克的代价就是从0点到那些城市的距离

求最少代价

题解:

点数很少,注意有重边

直接跑一发flyod,然后再来个背包dp

然后就好了~

代码:

 

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define test freopen("test.txt","r",stdin) #define maxn 2000001#define mod 10007#define eps 1e-9int Num;char CH[20];const int inf=0x3f3f3f3f;const ll infll = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}inline void P(int x){ Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts("");}//**************************************************************************************int dis[110][110];int dis1[110];int power[110];int dp[maxn];int main(){ //test; int t=read(); for(int cas=1;cas<=t;cas++) { int n=read(),m=read(); for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dis[i][j]=inf; for(int i=0;i
=dis1[i];j--) dp[j]=max(dp[j],dp[j-dis1[i]]+power[i]); int ans=inf; for(int i=0;i<=sum;i++) { if(dp[i]>=(aim/2+1)&&dp[i]
=inf) printf("impossible\n"); else printf("%d\n",ans); }}

 

转载地址:http://yplhl.baihongyu.com/

你可能感兴趣的文章
OpenWRT/LEDE长期运行记录截图
查看>>
执行计划--WHERE条件的先后顺序对执行计划的影响
查看>>
F - 概率(经典问题)
查看>>
不老的神器:安全扫描器Nmap渗透使用指南【转】
查看>>
Java-NIO(六):Channel聚集(gather)写入与分散(scatter)读取
查看>>
CUBA如何新增ServiceBean
查看>>
【技术文档】jeecg3.7-maven搭建好开发环境入门
查看>>
centos7 关闭firewall安装iptables并配置
查看>>
搜索7--noi1804:小游戏
查看>>
聊一聊分布式锁的设计
查看>>
模运算的规则
查看>>
Nginx + Tomcat 动静分离实现负载均衡
查看>>
浏览器配置工具.bat
查看>>
Image Filter
查看>>
项目笔记:新增、编辑与删除
查看>>
前向星和链式前向星
查看>>
3.1软件体系结构风格
查看>>
LinkedHashMap 源码解析
查看>>
Linux系统centOS7在虚拟机下的安装及XShell软件的配置
查看>>
网络知识 ACL NAT IPv6
查看>>