Test instructions is easier to understand: each point has a POW value, represents electricity, requires the dispatch of some tanks from point No. 0, occupy these points, so that the total POW value of the occupied point is greater than the POW in the whole diagram. And the tank consumes the smallest total oil, the number of tanks is unlimited.
Train of thought, after obtaining the unit shortest circuit, take POW as backpack, path length for items, solve 01 backpack. Then sweep back from half of the total value of the POW to get the minimum amount of oil (item).
#include <iostream> #include <queue> #include <vector> #include <stdio.h> #define INF 100000000using namespace Std;int n,m;int dist[105];int dp[10000000],pow[105];struct node{int e,w; Node (int ee,int ww): E (EE), W (WW) {} node () {} friend bool operator< (node N1,node n2) {return N1. W>n2. W }};vector<vector<node> >v;void Dijikstra () {for (int i=1;i<=n;i++) Dist[i]=inf; dist[0]=0; Priority_queue<node> Q; Q.push (Node (0,0)); while (! Q.empty ()) {node now=q.top (); Q.pop (); int S=now. E for (int i=0;i<v[s].size (); i++) {if (Dist[s]+v[s][i]. W<dist[v[s][i]. E]) {dist[v[s][i]. E]=dist[s]+v[s][i]. W Q.push (Node (v[s][i). E,dist[v[s][i]. E])); }}}}int Main () {int t,s,e,w,sum,ans; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n,&m); V.clear (); V.resize (n+1); sum=0; while (m--) {scanf ("%d%d%d", &s,&e,&w); V[s].push_back (Node (e,w)); V[e].push_back (Node (s,w)); } for (int i=1;i<=n;i++) {scanf ("%d", &pow[i]); Sum+=pow[i]; } Dijikstra (); for (int i=1;i<=sum;i++) Dp[i]=inf; dp[0]=0; for (int i=1;i<=n;i++) {for (int j=sum;j>=pow[i];j--) {dp[j]=min (dp[j],d P[j-pow[i]]+dist[i]); }} Ans=inf; for (int i=sum/2+1;i<=sum;i++) ans=min (Ans,dp[i]); if (Ans==inf) cout<< "Impossible" <<endl; else cout<<ans<<endl; } return 0;}
hdu3339 (dijkstra+ backpack)