HDU 5045 pressure DP Shanghai Online Competition

Source: Internet
Author: User

During the competition, I thought about putting n questions under pressure, but I couldn't pay attention to the order. At that time, I had a bad mental outlook and it was really frustrating.

In fact, another angle of this question is the arrangement of N numbers. If I perform pressure on N people and set a large cycle based on the question step by step, I will be the question at the moment, the previous I-1 question has been done, and then the person who has done it is in the status of J, J may be 1110 1101 1011 or something (assuming three questions have been done ), in this way, I can only keep the status in order. I only take the maximum value in this status. How can I arrange it in sequence?

So far... It seems that the problem is no problem, this practice repeats M/N times and finally run the remaining one, because every time I was considered only related to the I-1, you can use a rolling array. The trouble is that you need to clear the array each time. You can only say that the space and time cannot have both.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;double A[11][1010];int n,m;double dp[2][1<<11];int main(){    int t,kase=0;    scanf("%d",&t);    while (t--)    {        scanf("%d%d",&n,&m);        for (int i=0;i<n;i++){            for (int j=0;j<m;j++) scanf("%lf",&A[i][j]);        }        int ALL=1<<n;        for (int i=0;i<=ALL;i++){            dp[0][i]=dp[1][i]=0;        }        for (int i=0;i<n;i++){            dp[0][1<<i]=A[i][0];        }        int p=0;        double ans=0;        for (int i=1;i<m;i++){            p^=1;            for (int j=0;j<=ALL;j++) dp[p][j]=0;            for (int j=0;j<ALL;j++){                if (dp[p^1][j]==0) continue;                for (int k=0;k<n;k++){                    if ((1<<k)&j) continue;                    int nt=(1<<k)|j;                    if (nt==ALL-1) nt=0;                    dp[p][nt]=max(dp[p][nt],dp[p^1][j]+A[k][i]);                    if (i==m-1) ans=max(ans,dp[p][nt]);                }            }        }        printf("Case #%d: %.5lf\n",++kase,ans);    }}

 

HDU 5045 pressure DP Shanghai Online Competition

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.