UPC——2789: Selling CPUs(DP)

2789: Selling CPUs

传送门

时间限制: 1 Sec  内存限制: 64 MB
提交: 164  解决: 58
[提交] [状态] [讨论版] [命题人:admin]

题目描述

You are very happy, that you got a job at ACME Corporation’s CPU factory. After a hard month of labor, your boss has given you c identical CPUs as payment. Apparently, ACME Corporation is low on cash at the moment.
Since you can’t live on CPUs alone, you want to sell them on the market and buy living essentials from the money you make. Unfortunately, the market is very restrictive in the way you are allowed to conduct business. You are only allowed to enter the market once, you can only trade with each merchant once, and you have to visit the traders in a specific order. The market organizers have marked each merchant with a number from 1 to m (the number of merchants) and you must visit them in this order. Each trader has his own price for every amount of CPUs to buy.

输入

The input consists of:
• one line with two integers c and m (1 ≤ c, m ≤ 100), where c is the number of CPUs and m is the number of merchants;
• m lines describing the merchants. Each merchant is described by:
    – one line with c integers p 1 , . . . , p c (1 ≤ p i ≤ 10 5 for all 1 ≤ i ≤ c), where p i is the amount of money the merchant will give you for i CPUs.

输出

Output the maximum amount of money you can make by selling the CPUs you have.
Note that you don’t have to sell all CPUs.

样例输入

5 3
1 4 10 1 1
1 1 8 1 1
1 1 9 1 1

样例输出

13

来源/分类

GCPC2016 

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int c,m; 
int mp[105][105];
ll dp[105][105];
int main(void)
{
    scanf("%d%d",&c,&m);	
    memset(mp,0,sizeof(mp)); 
    for(int i=1;i<=m;i++)
    	for(int j =1;j<=c;j++)	
    		cin>>mp[i][j]; 
		
	memset(dp,0,sizeof(dp));
 	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=c;j++)
		{
			for(int k =c;k>=j;k++)    
				dp[i][j] = max(dp[i][j] , dp[i-1][k-j] + mp[i][k]);     
		}
	}
	cout<<dp[m][c]<<endl;  
}

猜你喜欢

转载自blog.csdn.net/Achanss/article/details/82947063