Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:贴代码,还是挺水的

Posted by 827695609 at 2018-04-16 15:46:19 on Problem 2385
In Reply To:贴代码,还是挺水的 Posted by:ACMore_txj at 2014-04-03 16:13:47
> #include<cstdio>
> #include<iostream>
> using namespace std;
> int a[1005],dp[10005][35];//dp[i][j],i分钟时用了j次移动后得到的苹果数目 
> int main()
> {
> 	int i,j,n,m,t,Max = 0;
> 	scanf("%d %d",&n,&m);
> 	for(i = 1;i <= n;i ++)
> 		scanf("%d",&a[i]);
> 	for(i = 1;i <= n;i ++)
> 	{
> 		dp[i][0] = dp[i-1][0] + 2 - a[i];//只要是移动0次,则一定在苹果树1的位置 
> 		for(j = 1;j <= m;j ++)//若j为奇数则在苹果树2位置,否则在1位置 
> 		{
> 			/*之所以现在移动步数为j,是从j-1步移动过来的,或者是和上一步一样没有动*/
> 			if(j % 2)
> 				dp[i][j] = max(dp[i-1][j-1],dp[i-1][j]) + a[i] - 1;
> 			else
> 				dp[i][j] = max(dp[i-1][j-1],dp[i-1][j]) + 2 - a[i];
> 		}
> 	}
> 	for(i = 0;i <= m;i ++)
> 		Max = max(Max,dp[n][i]);
> 	printf("%d\n",Max);
> 	return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator