*HDU3339 最短路+01背包
In Action
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5472 Accepted Submission(s): 1843
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.
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.
If not exist print "impossible"(without quotes).
//读错题了以为是只有一辆车。算出0点到每个点的最短路,以总路程为容量01背包找出取哪些点权值最大或以总权值为容量01背包出最小路程就行了,01背包又忘了。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int MAX=;
int mp[][],dis[],vis[],dp[],fei[];//dp别忘了开大
void dijk(int n)
{
for(int i=;i<=n;i++)
{
dis[i]=mp[][i];
vis[i]=;
}
vis[]=;
for(int i=;i<=n;i++)
{
int Min=MAX,sta=;
for(int j=;j<=n;j++)
{
if(!vis[j]&&dis[j]<Min)
{
Min=dis[j];
sta=j;
}
}
vis[sta]=;
for(int j=;j<=n;j++)
{
if(!vis[j]&&mp[sta][j]!=MAX&&dis[j]>dis[sta]+mp[sta][j])
dis[j]=dis[sta]+mp[sta][j];
}
}
}
int main()
{
int t,n,m,a,b,c;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
mp[i][j]=i==j?:MAX;
for(int i=;i<m;i++)
{
scanf("%d%d%d",&a,&b,&c);
mp[a][b]=mp[b][a]=min(mp[a][b],c);
}
int sum=;
for(int i=;i<=n;i++)
{scanf("%d",&fei[i]);sum+=fei[i];}
dijk(n);
int V=;
for(int i=;i<=n;i++)
{
if(dis[i]!=MAX) //去掉这样的点
V+=dis[i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
if(dis[i]==MAX) continue;
for(int j=V;j>=dis[i];j--)
dp[j]=max(dp[j],dp[j-dis[i]]+fei[i]);
}
int flag=;
for(int i=;i<=V;i++)
{
if(dp[i]>=sum/+)
{
printf("%d\n",i);
flag=;
break;
}
}
if(!flag) printf("impossible\n");
}
return ;
}
*HDU3339 最短路+01背包的更多相关文章
- 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 最短路+01背包
题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- In Action(最短路+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 ...
- hdu3339In Action(最短路+01背包)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...
- 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(Dijkstra +01背包)
Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the ...
- hdu 3339 In Action (最短路径+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- Java与MySQL的连接
下载数据库驱动文件,解压并保存至任意位置 下载地址 新建Java项目,并将驱动文件添加到项目中 项目名右键-->构建路径-->配置构建路径-->添加外部Jar 在项目中新建类,编写代 ...
- linux常用命令-用户管理命令
useradd 用户名 passwd 用户名:修改该用户的密码 groupadd 组名 who: 查看现在登录了几个用户,得到的信息含义如下 登录用户名 登录终端 登录时间 登录终端的IP地址(如果没 ...
- rsa 签名 加密解密
A->B 签名 ==========================A方+A方的私钥 => B收到后 用A方的公钥 验证签名 ==========================A-> ...
- 【Network】高性能 UDP 应该怎么做?
参考资料: EPOLL-UDP-GOLANG golang udp epoll - Google 搜索 go - golang: working with multiple client/server ...
- jstl 简单实践
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- 开发基于Edge渲染内核的浏览器应用
在使用Edge之前,我们先来看看UWP(Universal Windows Platform)平台.微软研发了多种设备平板.手机.Xbox.个人电脑等,在此之前,如果需要给每台设备开发程序,都需要对应 ...
- excel删除重复数据
1.点击任意单元格2.选择菜单栏的数据-->删除重复项 -->自定义重复
- HTML登录注册界面怎么制作?
在没有学习CSS样式的前提下,是如何做一个简单的注册界面的. 一.表单标签(form) 首先我们先写一个<form></form>的标签,form标签属于表单标签,通常我们的登 ...
- Java enum的用法详解[转]
Ref:http://www.cnblogs.com/happyPawpaw/archive/2013/04/09/3009553.html 用法一:常量 在JDK1.5 之前,我们定义常量都是: p ...
- sqlserver表分区小结
为什么要表分区? 当一个表的数据量太大的时候,我们最想做的一件事是什么?将这个表一分为二或者更多分,但是表还是这个表,只是将其内容存储分开,这样读取就快了N倍了 原理:表数据是无法放在文件中的,但是 ...