标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4141 Accepted Submission(s): 1964
题解:一次对行dp,一次对列dp;
java超时了。。。c就不会
代码:
import java.util.Scanner; public class Beans { static int a[] = new int[200010], dp[] = new int[200010], DP[] = new int[200010], b[] = new int[200010]; public static void main(String[] argvs){ int M, N; Scanner cin = new Scanner(System.in); while(cin.hasNext()){ M = cin.nextInt(); N = cin.nextInt(); for(int i = 0; i < M; i++){ DP[i] = 0; for(int j = 0; j < N; j++){ dp[j] = 0; a[j] = cin.nextInt(); if(j < 2) dp[j] = a[j]; else dp[j] = Math.max(dp[j - 2] + a[j], dp[j - 1]); } DP[i] = dp[N - 1]; if(i < 2) b[i] = DP[i]; else b[i] = Math.max(b[i - 2] + DP[i], b[i - 1]); } System.out.println(b[M - 1]); } } }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5478676.html