HDU 3339 In Action
来源:互联网 发布:伤害跳跃网络吧 编辑:程序博客网 时间:2024/05/09 01:44
In Action
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4325 Accepted Submission(s): 1395
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).
22 30 2 92 1 31 0 2132 12 1 313
5impossible
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<20
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int n,m;
int v;
int a,b,c;
int edge[110][110];
int sum;
int vis[110];int lowcost[110];
int dp[10011];
int val[110];
void dj()
{
cle(vis);
vis[0]=1;
for(int i=1;i<=n;i++)
lowcost[i]=edge[0][i];
int Min,k;
while(1)
{
Min=INF;
for(int i=1;i<=n;i++)
if(lowcost[i]<Min&&!vis[i])
{
Min=lowcost[i];k=i;
}
if(Min==INF)break;
vis[k]=1;
for(int j=1;j<=n;j++)
if(lowcost[k]+edge[k][j]<lowcost[j]&&!vis[j])
lowcost[j]=lowcost[k]+edge[k][j];
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--)
{
sum=0;
scanf("%d%d",&n,&m);
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
edge[i][j]=INF;
edge[i][i]=0;
}
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(edge[a][b]>c)
{
edge[a][b]=c;edge[b][a]=c;
}
}
for(int i=1;i<=n;i++)
{
cin>>val[i];
sum+=val[i];
}
dj();
v=0;int mark=0;
for(int i=1;i<=n;i++)
{
v+=lowcost[i];
if(lowcost[1]==INF)
{
mark=1;break;
}
}
cle(dp); ///把总费用当作体积 价值为val[] dp[j]为在体积小于等于 V 能达到的最大价值
if(mark)printf("impossible\n");
else
{
for(int i=1;i<=n;i++)
for(int j=v;j>=lowcost[i];j--)
dp[j]=max(dp[j],dp[j-lowcost[i]]+val[i]);
for(int i=1;i<=v;i++)
if(dp[i]>=sum/2+1){cout<<i<<endl;break;}
}
//system("pause");
}
return 0;
}
- HDU 3339 In Action
- hdu 3339 In Action
- hdu 3339 In Action
- hdu 3339 In Action
- hdu 3339 In Action
- hdu 3339 In Action
- hdu 3339 In Action
- hdu 3339:In Action
- HDU 3339 In Action
- HDU 3339 In Action
- HDU 3339 In Action
- HDU 3339 In Action
- HDU-3339-In Action
- HDU 3339-In Action
- HDU 3339 In Action
- HDU-3339-In Action(Dijkstra+01背包)
- HDU 3339--In Action【Floyd+01背包】
- hdu 3339 In Action shortest path
- POJ 1125 Stockbroker Grapevine
- HDU 1548 A strange lift
- Bellman-ford模板
- HDU 1317 XYZZY
- HDU 1535 Invitation Cards
- HDU 3339 In Action
- IOS获取系统通讯录联系人信息
- HDU 2647 Reward(拓扑排序)
- 栈的应用--括号匹配的检验(C++)
- HDU 5055 Bob and math problem
- Toast提示内容简单介绍
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDU 2962 Trucking
- A Mathematical Curiosity