Selling CPUs(DP)

探讨了在特定市场规则下,如何通过动态规划算法实现CPU商品的最大化销售收益。问题设定为拥有一定数量的CPU,面对顺序排列且各具报价的商家,需决定最佳出售方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

### CPU 详细信息概述 CPU 的详细信息可以通过多种方式获取,具体取决于操作系统和工具的选择。以下是关于 CPU 详细信息的几个关键点: #### 1. 查看 CPU 基本信息 在 Linux 系统中,可以使用 `cat /proc/cpuinfo` 命令查看 CPU 的详细信息,包括型号、主频、缓存大小等[^1]。例如: ```bash cat /proc/cpuinfo ``` 输出中包含以下字段: - **model name**: 表示 CPU 的全名,包括品牌和具体型号。 - **processor**: 表示逻辑处理器编号。 - **cpu MHz**: 表示当前 CPU 的主频。 #### 2. 查看核心数和线程数 在 Windows 系统中,可以通过任务管理器的“性能”标签页查看 CPU 的核心数和线程数[^2]。此外,在 Linux 系统中,`lscpu` 命令可以提供更详细的 CPU 信息,包括物理核心数、逻辑核心数以及每个核的线程数[^3]。例如: ```bash lscpu ``` 输出中包含以下字段: - **Core(s) per socket**: 每个插槽上的物理核心数。 - **Thread(s) per core**: 每个物理核心对应的线程数。 - **Socket(s)**: 物理 CPU 插槽数。 #### 3. 查看架构和其他技术参数 通过 `lscpu` 命令还可以获取 CPU 的架构信息,如 x86_64 或 ARM,并了解字节顺序(Little Endian 或 Big Endian)以及其他技术细节[^3]。 #### 示例代码 以下是一个简单的脚本,用于在 Linux 系统中提取 CPU 的相关信息: ```bash #!/bin/bash echo "CPU 详细信息如下:" echo "-------------------" echo "Model Name: $(grep 'model name' /proc/cpuinfo | uniq | cut -d ':' -f 2)" echo "Processor Count: $(nproc)" echo "CPU MHz: $(lscpu | grep 'CPU MHz' | cut -d ':' -f 2)" echo "Core(s) per Socket: $(lscpu | grep 'Core(s) per socket' | cut -d ':' -f 2)" echo "Thread(s) per Core: $(lscpu | grep 'Thread(s) per core' | cut -d ':' -f 2)" ``` #### 总结 通过上述方法,可以全面了解 CPU 的详细信息,包括型号、主频、核心数、线程数以及架构等。这些信息对于系统优化、性能分析和硬件选型具有重要意义。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值