Test instructions: give you a graph and the value of each point, the margin value is connected to two points of the weight of the product, go to the Hamilton path, if the arrival point and the last point is connected to the value plus three point product, to find the maximum value of the Hamiltonian path, and the maximum value of the Hamiltonian channel number.
Analysis: Start to look at the problem is very scary, but think about the state of the problem OK Dp[i][j][k] means I have traversed the point of the situation, the current point is J before a point for the maximum value of K, enumerate all possible cases, and then how to find the number Ah,
Tangled up for a long time, only to find and in the value of the original value when the same, then add the original state contains the number of bars, if the maximum value is updated, this number is the current state of the number of bars, but also note that two completely reverse path as a path.
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cctype> #include <complex> #include <cassert> #include <utility> #include <cstring> #include <cstdlib># Include <iostream> #include <algorithm>using namespace std;typedef pair<int,int> pii;typedef long Long ll; #define Lson l,m,rt<<1#define Pi ACOs ( -1.0) #define Rson m+1,r,rt<<11#define all 1,n,1#define read fre Open ("In.txt", "R", stdin) #define N 1<<13const ll infll = 0x3f3f3f3f3f3f3f3fll;const int inf= 0x7ffffff;const int m od = 1000000007;int n,m,con[15][15],v[15];ll dp[n][15][15],num[n][15][15];void solve () {memset (dp,-1,sizeof (DP)); memset (num,0,sizeof (num)); int cas= (1<<n)-1; dp[0][0][0]=0; for (int i=1;i<=n;++i) {dp[1<< (i-1)][0][i]=v[i]; num[1<< (i-1)][0][i]=1; } for (int i=1;i<=cas;++i) {for (int j=1;j<=n;++j) {if (!) ( i& (1<< (j-1))) continue; for (int k=0;k<=n;++k) {if (j==k) continue; if (k==0&&! ( i& (1<< (j-1))) | | k!=0&&! (i& (1<< (k-1)))) Continue if (dp[i][k][j]==-1) continue; for (int l=1;l<=n;++l) {if (!) ( i& (1<< (L-1))) &&con[j][l]) {int t=i+ (1<< (L-1)); ll tot=v[l]* (v[j]+1); if (Con[l][k]) tot+=v[k]*v[j]*v[l]; TOT+=DP[I][K][J]; if (Dp[t][j][l]<tot) {dp[t][j][l]=tot; NUM[T][J][L]=NUM[I][K][J]; } else if (Dp[t][j][l]==tot) {num[t][j][l]+=num[i][k][j]; }}}}} ll maxv=-1,sum=0; for (int. i=0;i<=n;++i) for (int j=0;j<=n;++j) Maxv=max (Maxv,dp[cas][i][j]); if (maxv==-1) printf("0 0\n"); else{for (int i=0;i<=n;++i) for (int j=0;j<=n;++j) if (Maxv==dp[cas][i][j]) sum+=num[cas][i][j]; printf ("%i64d%i64d\n", maxv,sum/2?sum/2:1); }}int Main () {int q; scanf ("%d", &q); while (q--) {scanf ("%d%d", &n,&m); for (int i=1;i<=n;++i) scanf ("%d", &v[i]); int x, y; memset (Con,0,sizeof (con)); while (m--) {scanf ("%d%d", &x,&y); Con[x][y]=1; Con[y][x]=1; } solve (); }return 0;}
Islands and Bridges (POJ 2288-like pressure DP)