Selling CPUs(DP)

[提交] [状态] [讨论版] [命题人: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

题意:这个人有c件商品,有m个买家,每个买家对着c件商品的出价不同,一个买家最多只能买一件,而且是严格的从1到m个买家卖出,c件商品的卖出顺序 第 j 个买家买了第 i 个商品,那么第 j +1 个买家必须买大于 i 的商品,商品可以不都卖出,问最多可以卖多少钱

使用DP ,maze[ i ] [ j ] 代表第 i 个买家买了第 j 件商品所得钱数,然后DP 即可得到最大钱数

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int maze[110][110];
int a[110][110];
int main()
{
	int c,m;
	scanf("%d %d",&c,&m);
	for(int i=1;i<=m;i++){
		for(int j=1;j<=c;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	memset(maze,0,sizeof(maze));
   	int temp=a[m][1];
    for(int i=1;i<=c;i++){
        temp=max(temp,a[m][i]);
		maze[m][i]=temp;
    }
    
    for(int i=m;i>=1;i--){
        for(int j=c;j>=1;j--){
			maze[i][j]=maze[i+1][j];
            for(int t=1;t<=j;t++)
                maze[i][j]=max(maze[i+1][j-t]+a[i][t],maze[i][j]);
        }
    }

	int maxn=0;
	for(int i=1;i<=c;i++)
		maxn=max(maxn,maze[1][i]);
		
	printf("%d\n",maxn);
	
	return 0;
 } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值