Most Powerful (DP-like water pressure problem)

Topic links:

https://ac.nowcoder.com/acm/problem/15832

Subject to the effect:

Own translation, note that each collision is one of the two disappear, not two are gone

Specific ideas:

dp [i] i represents the largest state how much energy is triple for the cycle enumeration

AC Code:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 # define ll long long
 4 # define inf 0x3f3f3f3f
 5 # define LL_inf (1ll<<60)
 6 const int maxn = 2e5+100;
 7 int dp[1024+100];
 8 int a[15][15];
 9 int main()
10 {
11     int n;
12     while(~scanf("%d",&n)&&n)
13     {
14         memset(dp,0,sizeof(dp));
15         for(int i=0; i<n; i++)
16         {
17             for(int j=0; j<n; j++)
18             {
19                 scanf("%d",&a[i][j]);
20             }
21         }
22         int maxstate=(1<<n)-1;
23         int maxx=0;
24         for(int i=0; i<=maxstate; i++)
25         {
26             for(int j=0; j<n; j++)
27             {
28                 for(int k=0; k<n; k++)
29                 {
30                     if(k==j)
31                         continue;
32                     if((i&(1<<j))==0 && (i&(1<<k))==0)
33                         dp[i^(1<<j)]=max(dp[i^(1<<j)],dp[i]+a[k][j]);
34                     maxx=max(maxx,dp[i^(1<<j)]);
35                 }
36             }
37         }
38         printf("%d\n",maxx);
39     }
40     return 0;
41 }

acm career should be on this end of the

Guess you like

Origin www.cnblogs.com/letlifestop/p/11098159.html