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

开二维绝对ce,建议开一维

Posted by 201925220524 at 2020-01-07 23:54:01 on Problem 3624
#include<iostream>
#include<cstring>
using namespace std;
int w[3501]={0};
int d[3501]={0};
int dp[13000];
int main()
{
	int n,m;
	cin>>n>>m;
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
		cin>>w[i]>>d[i];
	for(int i=1;i<=n;i++)
		for(int j=m;j>=0;j--)
			if(j-w[i]>=0)
				dp[j]=max(dp[j-w[i]]+d[i],dp[j]);
			//else dp[i][j]=dp[i-1][j];
	cout<<dp[m]<<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