Test instructions: N atoms, 22 collide one disappears, generating energy, giving the energy that any two atoms collide with to generate the maximum energy.
Analysis: Dp[i] represents the maximum energy generated when the condition is I
/* #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) const LL INFLL = 0x3f3f3f3f3f3f3f3fll;const int inf= 0x7ffffff;const int mod = 1000000007;int N,dp[2000],a[15][15];void solve () {memset (dp,0,sizeof (DP)); for (int i= (1<<n) -1;i>0;--i) {int maxv=0,m=i; for (int j=0;j<n;++j) {if ((m&1) ==0) {int maxp=0,t=i; for (int k=0;k<n;++k) {if (t&1) &&A[K][J]>MAXP) Maxp=a[k][j]; t>>=1; } if (dp[i^ (1<<j)]+maxp>maxv) maxv=dp[i^ (1<<j)]+maxp; } m>>=1; } DP[I]=MAXV; } int maxpow=-1; for (int i=0;i<n;++i) {if (maxpow<dp[(1<<i))) maxpow=dp[(1<<i)]; cout<<dp[(1<<i)]<<endl; } printf ("%d\n", Maxpow);} int main () {while (~SCANF ("%d", &n)) {if (n==0) break; for (int i=0;i<n;++i) for (int j=0;j<n;++j) scanf ("%d", &a[i][j]); Solve (); }return 0;} *///#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#de Fine Read freopen ("In.txt", "R", stdin) const LL INFLL = 0x3f3f3f3f3f3f3f3fll;const int inf= 0x7ffffff;const int mod = 10 00000007;int dp[1100],n;int power[15][15];void Solve () {memset (dp,0,sizeof (DP)); int cas= (1<<N); for (int i=0;i<cas;++i) for (int j=0;j<n;++j) {if ((i& (1<<J))) continue; int maxv=-1; for (int k=0;k<n;++k) if ((i& (1<<k)) ==0&&j!=k) dp[i| ( 1<<J)]=max (dp[i| ( 1<<J)],dp[i]+power[k][j]); } int maxv=-1; for (int i=0;i<cas;++i) Maxv=max (Maxv,dp[i]); printf ("%d\n", MAXV);} int main () {while (~SCANF ("%d", &n)) {if (n==0) break; for (int i=0;i<n;++i) for (int j=0;j<n;++j) scanf ("%d", &powerI [j]); Solve (); }return 0;}
Most powerful (ZOJ 3471 pressure DP)