XTU-1231 Life Achievement (DP + records the number of optimal solutions)

Source: Internet
Author: User

http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1231

Direct recursion.

Save the maximum number of paths to the maximum value at the same time, and note the first column of the first row.

Don't forget to take the mold.

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5 Const intMAXN =510;6 intDP[MAXN][MAXN],P[MAXN][MAXN],Q[MAXN][MAXN];7 intMain ()8 {9     intN;Ten      while(~SCANF ("%d",&N)) One     { AMemset (DP,0,sizeof(DP)); -          for(intI=1; i<=n;i++) { -              for(intj=1; j<=n;j++) { thescanf"%d",&p[i][j]); -q[i][j]=1; -             } -         } +          for(intI=1; i<=n;i++) { -              for(intj=1; j<=n;j++) { +                 if(dp[i-1][j]>dp[i][j-1]) { Adp[i][j]=dp[i-1][j]+P[i][j]; at                     if(i==1|| j==1)Continue; -q[i][j]=q[i-1][j]; -                 } -                 Else if(dp[i][j-1]>dp[i-1][j]) { -dp[i][j]=dp[i][j-1]+P[i][j]; -                     if(i==1|| j==1)Continue; inq[i][j]=q[i][j-1]; -                 } to                 Else { +dp[i][j]=dp[i-1][j]+P[i][j]; -                     if(i==1|| j==1)Continue; theq[i][j]=q[i-1][j]+q[i][j-1]; *                 } $q[i][j]%=123456;Panax Notoginseng             } -         } the     //for (int i=1;i<=n;i++) { +           //for (int j=1;j<=n;j++) A              //printf ("%d", q[i][j]); the            //printf ("\ n"); +         //} -printf"%d\n", q[n][n]%123456); $     } $     return 0; -}
View Code

XTU-1231 Life Achievement (DP + records the number of optimal solutions)

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.