In Action

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5472    Accepted Submission(s): 1843

Problem 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
 
Author
Lost@HDU
 
Source
 
题意:
有n+1个点,m条路,0点是起点,除0点外每个点有一个权值,经过每条路会有相应的油费,若干辆车从0点出发去占领点,要占领一半以上的总权值才行,问最少的油费。
代码:
  1. //读错题了以为是只有一辆车。算出0点到每个点的最短路,以总路程为容量01背包找出取哪些点权值最大或以总权值为容量01背包出最小路程就行了,01背包又忘了。。。
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. const int MAX=;
  8. int mp[][],dis[],vis[],dp[],fei[];//dp别忘了开大
  9. void dijk(int n)
  10. {
  11. for(int i=;i<=n;i++)
  12. {
  13. dis[i]=mp[][i];
  14. vis[i]=;
  15. }
  16. vis[]=;
  17. for(int i=;i<=n;i++)
  18. {
  19. int Min=MAX,sta=;
  20. for(int j=;j<=n;j++)
  21. {
  22. if(!vis[j]&&dis[j]<Min)
  23. {
  24. Min=dis[j];
  25. sta=j;
  26. }
  27. }
  28. vis[sta]=;
  29. for(int j=;j<=n;j++)
  30. {
  31. if(!vis[j]&&mp[sta][j]!=MAX&&dis[j]>dis[sta]+mp[sta][j])
  32. dis[j]=dis[sta]+mp[sta][j];
  33. }
  34. }
  35. }
  36. int main()
  37. {
  38. int t,n,m,a,b,c;
  39. scanf("%d",&t);
  40. while(t--)
  41. {
  42. scanf("%d%d",&n,&m);
  43. for(int i=;i<=n;i++)
  44. for(int j=;j<=n;j++)
  45. mp[i][j]=i==j?:MAX;
  46. for(int i=;i<m;i++)
  47. {
  48. scanf("%d%d%d",&a,&b,&c);
  49. mp[a][b]=mp[b][a]=min(mp[a][b],c);
  50. }
  51. int sum=;
  52. for(int i=;i<=n;i++)
  53. {scanf("%d",&fei[i]);sum+=fei[i];}
  54. dijk(n);
  55. int V=;
  56. for(int i=;i<=n;i++)
  57. {
  58. if(dis[i]!=MAX) //去掉这样的点
  59. V+=dis[i];
  60. }
  61. memset(dp,,sizeof(dp));
  62. for(int i=;i<=n;i++)
  63. {
  64. if(dis[i]==MAX) continue;
  65. for(int j=V;j>=dis[i];j--)
  66. dp[j]=max(dp[j],dp[j-dis[i]]+fei[i]);
  67. }
  68. int flag=;
  69. for(int i=;i<=V;i++)
  70. {
  71. if(dp[i]>=sum/+)
  72. {
  73. printf("%d\n",i);
  74. flag=;
  75. break;
  76. }
  77. }
  78. if(!flag) printf("impossible\n");
  79. }
  80. return ;
  81. }

*HDU3339 最短路+01背包的更多相关文章

  1. HDU 3339 In Action【最短路+01背包】

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Other ...

  2. HDU 3339 In Action【最短路+01背包模板/主要是建模看谁是容量、价值】

     Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the n ...

  3. HDU 3339 In Action 最短路+01背包

    题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  4. In Action(最短路+01背包)

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. HDU 3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. hdu3339In Action(最短路+01背包)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...

  7. hdoj--3339--In Action(最短路+01背包)

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. HDU-3339 IN ACTION(Dijkstra +01背包)

      Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the ...

  9. hdu 3339 In Action (最短路径+01背包)

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. Java 程序的内存泄露问题分析

    什么是内存泄露? 广义的Memory Leak:应用占用了内存,但是不再使用(包括不能使用)该部分内存 狭义的Memory Leak:应用分配了内存,但是不能再获取该部分内存的引用(对于Java,也不 ...

  2. 【荐2】Total Commander 7.57 配置选项 个性化设置备份,,,开启时如何自动最大化???(二)

    最近安装了下新版的“Total Commander 7.56”,发现它的默认设置是如此的不好用,现把对其个性化设置备份如下(符合大部分用户的操作习惯): 默认打开Total Commander 7.5 ...

  3. 去除ios系统a标签点击时的灰色背景

    使用图片作为a标签的点击按钮时,当触发touchstart的时候,往往会有一个灰色的背景,想要去掉的话可以用下面这种方式 a,a:hover,a:active,a:visited,a:link,a:f ...

  4. css特殊字符总结

    < :    &lt > :    &gt

  5. 使用Notepad++实现批量将ANSI转成为UTF-8编码

    http://blog.sina.com.cn/s/blog_5f4150730101b3ok.html 使用Trados2011翻译英文html后,如果是单个文件,可在另存译文时选择Encoding ...

  6. Ackerman函数的栈实现

    一.Ackerman函数: ackerman函数的定义如下: 二.Ackerman函数的递归实现: 利用递归来实现ackerman函数是比较简单的: /*Sample Input: 0 1 1 1 S ...

  7. 【转】sed 简明教程

    本文转自:http://coolshell.cn/articles/9104.html awk于1977年出生,今年36岁本命年,sed比awk大2-3岁,awk就像林妹妹,sed就是宝玉哥哥了.所以 ...

  8. Unity3D 查找Update函数体为空的类

    如果是大项目,有很多Update空跑还是多少有些效率损耗,那我们就把他们都找出来. 先引用Mono.Cecil //代码 using UnityEngine; using UnityEditor; u ...

  9. ABAP 数量单位转换

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'           EXPORTING             input                = wa_ite ...

  10. 【目录】python

    python 入门学习(一) 入门学习(二) 入门学习(三) 入门学习(四) 入门学习(五) 入门学习(六) 入门学习(七) 入门学习(八) 入门学习(九) 入门学习(十) Head First Py ...