Usaco score inflation, complete backpack problem

Source: Internet
Author: User

It's a classic complete backpack problem.
My Code

/* 
id:wangxin12 
prog:inflate
lang:c++ */ 
#include <iostream>
#include <fstream >
using namespace std;
#define MAX 10000

int M, N;
int Point[max + 1]; Points 
int Miniute[max + 1];  miniutes
int Dp[max + 1];

int main () {
	ifstream fin ("inflate.in");
	Ofstream fout ("Inflate.out");

	int I, J;
	fin>>m>>n;
	for (i = 1; I <= N; i++) {
		fin>>point[i]>>miniute[i];
		Dp[i] = Point[i];
	}

	Init, dp[1], when only the first item is loaded for
	(j = 0; J <= M; j + +) {
		Dp[j] = (j/miniute[1]) * point[1]; 
	}

	Start with the second item for dynamic planning for
	(i = 2; I <= N; i++) {for
		(j = miniute[i]; j <= M; j + +) {
			//state transfer equation
			dp[j] = (Dp[j] > dp[j-miniute[i]] + point[i])? DP[J]: dp[J-miniute[i]] + point[i];
		}
	}

	fout<<dp[m]<<endl;

	return 0;
}


--------------------------------------------------------------------------------------------------------------- ---------

The more points students score in our contests, the happier we here at the Usaco is. We try to design our contests so this people can score as many points as possible, and would like your assistance.

We have several categories from which problems can being chosen, where a "category" is an unlimited set of contest problems W Hich all require the same amount of time-to-solve and deserve the same number of points for a correct solution. Your task is write a program which tells the Usaco staff how many problems from each category to include in a contest so a s to maximize the total number of points in the chosen problems while keeping the total solution time within the length of The contest.

The input includes the length of the contest, M (1 <= m <=) (don ' t worry, you won ' t has to compete in the LO Nger contests until training camp) and N, the number of problem categories, where 1 <= N <= 10,000.

Each of the subsequent N lines contains, integers describing a category:the first integer tells the number of points a Problem from this category is worth (1 <= points <= 10000); The second tells the number of minutes a problem from that category takes to solve (1 <= minutes <= 10000).

Your program should determine the number of problems we should take from each category to make the highest-scoring contest Solvable within the length of the contest. Remember, the number from any category can is any nonnegative integer (0, one, or many). Calculate the maximum number of possible points. Program Name:inflate INPUT FORMAT

Line 1: M, N--contest minutes and number of problem classes
Lines 2-n+1: Integers:the points and minutes for each class
SAMPLE INPUT (file inflate.in)
4
35 20
OUTPUT FORMAT

A single line with the maximum number of points possible given the constraints. SAMPLE OUTPUT (file inflate.out)

605

(Take the problems from #2 and three from #4.)

Description

The more students score in our Usaco competition, the happier we are.

We try to design our contests so that people can score as many points as possible, which requires your help.

We can choose the topic of the contest from several kinds, here a "kind" refers to a collection of contest topics, solve the problem in the collection of the same time and can get the same score. Your task is to write a program to tell Usaco's staff how many topics should be chosen from each category, so that the total time to solve the problem will be the maximum amount for the duration of the contest. Enter the time to include the contest, M (1 <= m <= 10,000) (Don't worry, you will have a long game at the camp) and N, the number of "species" 1 <= n <= 10,000. Each subsequent line will consist of two integers describing a "kind":

The first integer shows the score (1 <= points <= 10000) that solves this problem, and the second integer indicates the time required to resolve the problem (1 <= minutes <= 10000). Your program should determine how many titles we should choose from each "category" to get the maximum score for the duration of the contest.

The number of topics from any "kind" may be any non-negative (0 or more).

Calculates the maximum score that may be obtained.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.