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

贴个c++代码,单数列递推

Posted by a280920481 at 2018-12-05 23:12:33 on Problem 3624
#include <iostream>
using namespace std;


int sum[12881];
int weight[3402];
int desirability[3402];


int main()
{
	int N, M, w, d;

	cin >> N >> M;

	for (int i = 0; i < N; i++)
	{
		cin >> weight[i] >> desirability[i];
	}


	for (int f = 0; f < N; f++)
	{
		w = weight[f];
		d = desirability[f];

		for (int i = M; i >= w; i--)
		{
			if (sum[i - w] + d > sum[i])
			{
				sum[i] = sum[i - w] + d;
			}		
		}
	}

	cout << sum[M] << '\n';
	
	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