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

我要晕死了,无语了,该啊该啊,第一次写dp,被边界弄死了

Posted by TSERROF at 2012-10-21 16:50:23 on Problem 1163
#include<iostream>
#include <cstring>
using namespace std;
const int INF=0x7fffffff-1000;
int table[105][105],dp[105][105];  //dp[i][j]表示把i束花放入前j个花瓶的最大价值
int main()
{
	int F,V;
	while(cin>>F>>V)
	{
		for(int i=0;i<105;++i)
			for(int j=0;j<105;++j)
				dp[i][j]=-INF;
		for(int i=1;i<=F;++i)
			for(int j=1;j<=V;++j)
				cin>>table[i][j];
		for(int j=1;j<=V;++j)
		{
			for(int i=1;i<=min(j,F);++i)
			{
				int t=dp[i-1][j-1]==-INF?0:dp[i-1][j-1];
				dp[i][j]=max(dp[i][j-1],t+table[i][j]);
			}
		}
		cout<<dp[F][V]<<endl;
	}
	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