HDU 3339 In Action(迪杰斯特拉+01背包)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=3339
In Action
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7869 Accepted Submission(s): 2674

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).
2 3
0 2 9
2 1 3
1 0 2
1
3
2 1
2 1 3
1
3
impossible
#include <iostream>
#include <cstdio>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<memory>
#include<queue>
#include<vector>
using namespace std;
typedef long long LL;
#define max_v 10005
#define INF 99999999 int dp[max_v];
int v[max_v];
int cost[max_v]; int e[max_v][max_v];
int n,m;
int used[max_v];
int dis[max_v];
void init()
{
memset(used,,sizeof(used));
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
e[i][j]=INF;
}
dis[i]=INF;
}
}
void Dijkstra(int s)
{
for(int i=; i<=n; i++)
{
dis[i]=e[s][i];
}
dis[s]=;
for(int i=; i<=n; i++)
{
int index,mindis=INF;
for(int j=; j<=n; j++)
{
if(used[j]==&&dis[j]<mindis)
{
mindis=dis[j];
index=j;
}
}
used[index]=;
for(int j=; j<=n; j++)
{
if(dis[index]+e[index][j]<dis[j])
dis[j]=dis[index]+e[index][j];
}
}
}
void ZeroOnePack_improve(int n,int c)
{
memset(dp,,sizeof(dp));
for(int i=; i<=n; i++)
{
for(int j=c; j>=cost[i]; j--)
{
dp[j]=max(dp[j],dp[j-cost[i]]+v[i]); }
}
}
int main()
{
int t;
int a,b,c;
int sum;
int sumv;
int flag;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&m);
n++;
init();
for(int i=; i<m; i++)
{
scanf("%d %d %d",&a,&b,&c);
a++;
b++;
if(e[a][b]>c)
e[a][b]=e[b][a]=c;
}
sumv=;
for(int i=; i<=n-; i++)
{
scanf("%d",&v[i]);//价值
sumv+=v[i];
} Dijkstra();
int k=;
sum=;
for(int i=; i<=n; i++)
{
cost[k++]=dis[i];//花费
if(dis[i]!=INF)//wa点
sum+=dis[i];
}
ZeroOnePack_improve(k-,sum);
flag=;
for(int i=; i<=sum; i++)
{
if(dp[i]>=sumv/+)
{
flag=;
printf("%d\n",i);
break;
}
}
if(flag==)
printf("impossible\n");
}
return ;
}
HDU 3339 In Action(迪杰斯特拉+01背包)的更多相关文章
- hdu 3339 In Action(迪杰斯特拉+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 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 2680 最短路 迪杰斯特拉算法 添加超级源点
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 2544最短路 (迪杰斯特拉算法)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2544 最短路 Time Limit: 5000/1000 MS (Java/Others) Me ...
- HDU 3790(两种权值的迪杰斯特拉算法)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3790 最短路径问题 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1874畅通工程续(迪杰斯特拉算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 畅通工程续 Time Limit: 3000/1000 MS (Java/Others) ...
- hdu 1142(迪杰斯特拉+记忆化搜索)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- hdu 1595 find the longest of the shortest(迪杰斯特拉,减去一条边,求最大最短路)
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 ...
随机推荐
- [POI2013]LUK-Triumphal arch
题目链接 此题的答案k具有可二分性 那么我们可以二分答案k,然后跑一个树形DP 令\(dp[i]\)表示到节点\(i\)时需要再多染色的点数 那么有\(dp[i]=\max(\sum_{fa[j]=i ...
- bootStrap下拉菜单 点击下拉列表某个元素,列表不隐藏
html: <a class="dropdown-toggle bgImg-priceWran " id="dropdownMenu1" data-tog ...
- 线程Event事件
事件(event) 事件是不同线程之间的同步对象 enent可以通过设置.等待.清除一个标识(flag),来进行线程间的控制 线程可以通过获取这个标志位(flag)的状态(设置或未设置)来控制线程 事 ...
- Struts 2 官方文档中文版
最近正在学 Struts 2 ,咱英文水平不行啊,找到了<Struts 2 官方文档中文版>,虽然翻译的不全,有总比没有强. 地址:https://cwiki.apache.org/con ...
- 译文 [ROM][多国语言][2015.06.11] Lenovo S750 (MTK6589) - andrea_d86-lenovos750-4.2.2
************************************************** andrea_d86-lenovos750-4.2.2-150530 ************** ...
- CAShapeLayer的使用[1]
CAShapeLayer的使用[1] 使用CoreAnimation绘制动画带来的系统开销非常的小,CoreAnimation通常都是使用GPU的. CAShapeLayer属于CoreAnimati ...
- Python学习---Django路由系统【all】
Django URL (路由系统) Django URL (路由系统): URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及要为该URL模式调用的视图函数之间的映 ...
- HTML学习---HTML状态码
301 Moved Permanently 永久移动.请求的资源已被永久的移动到新URI,返回信息会包括新的URI,浏览器会自动定向到新URI.今后任何新的请求都应使用新的URI代替302 Found ...
- TMG 2010 使用脚本来导入URL集和域名集
作为一个网管,相信有领导叫你限制员工上网的情况,例如只限制员工访问某些网站.在禁止的网站数量少的时候,添加URL集或者域名集是一件很简单的事情,如果禁止的网站数量多达1500个呢?如果再使用ISA S ...
- [BZOJ 3441]乌鸦喝水
3441: 乌鸦喝水 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 374 Solved: 148[Submit][Status][Discuss] ...