Most powerful (ZOJ 3471 pressure DP)

Source: Internet
Author: User

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) &&AMP;A[K][J]&GT;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&LT;&LT;N);        for (int i=0;i<cas;++i) for (int j=0;j<n;++j) {if ((i& (1&LT;&LT;J))) continue;        int maxv=-1; for (int k=0;k<n;++k) if ((i& (1<<k)) ==0&&j!=k) dp[i| ( 1&LT;&LT;J)]=max (dp[i| (    1&LT;&LT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.