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

滚动数组啊

Posted by cailongx at 2013-04-26 15:32:45 on Problem 3624
int main()
{
	int N,M;
	cin>>N>>M;
	int cost[3403];
	int value[3403];
	for (int i=1; i<=N; i++)
	{
		cin>>cost[i]>>value[i];
	}
	
	
	int F[2][13000] = {0}; 

	for (int i=1; i<= N; i++)
	{
		for (int v=0; v<cost[i]; v++)
		{
			F[i%2][v] = F[(i-1)%2][v];
		}
		for (int v=cost[i]; v<=M; v++)
		{
			F[i%2][v] = max(F[(i-1)%2][v], F[(i-1)%2][v-cost[i]] + value[i]);
		}
	}
	cout<<F[N%2][M];

	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