题目如下:

Description

A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precisely one unit of time for being sold. A selling schedule is an ordered subset of products Sell ≤ Prod such that the selling of each product x∈Sell, according to the ordering of Sell, completes before the deadline dx or just when dx expires. The profit of the selling schedule is Profit(Sell)=Σ x∈Sellpx. An optimal selling schedule is a schedule with a maximum profit.
For example, consider the products Prod={a,b,c,d} with (pa,da)=(50,2), (pb,db)=(10,1), (pc,dc)=(20,2), and (pd,dd)=(30,1). The possible selling schedules are listed in table 1. For instance, the schedule Sell={d,a} shows that the selling of product d starts at time 0 and ends at time 1, while the selling of product a starts at time 1 and ends at time 2. Each of these products is sold by its deadline. Sell is the optimal schedule and its profit is 80.

Write a program that reads sets of products from an input text file and computes the profit of an optimal selling schedule for each set of products.

Input

A set of products starts with an integer 0 <= n <= 10000, which is the number of products in the set, and continues with n pairs pi di of integers, 1 <= pi <= 10000 and 1 <= di <= 10000, that designate the profit and the selling deadline of the i-th product. White spaces can occur freely in input. Input data terminate with an end of file and are guaranteed correct.

Output

For each set of products, the program prints on the standard output the profit of an optimal selling schedule for the set. Each result is printed from the beginning of a separate line.

Sample Input

4  50 2  10 1   20 2   30 17  20 1   2 1   10 3  100 2   8 25 20  50 10

Sample Output

80
185

Hint

The sample input contains two product sets. The first set encodes the products from table 1. The second set is for 7 products. The profit of an optimal schedule for these products is 185.

 思路:

我们获得的最大利润是将商品全部卖出。而无法被卖出的商品,一定有商品与它在同一天过期,在当天,卖出利润最高的即可。

源代码:

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int const N = 10005;
int isfree[N]; 
struct node{
    int p,d;
};
node pro[N];

bool cmp(const node& a,const node& b){
    if(a.p == b.p)return a.d < b.d;
    else return a.p > b.p;
}

int main(){
    int n,ans;
    while(cin >> n){
        ans = 0;
        for(int i = 1;i <= n;i++){
            cin >> pro[i].p >> pro[i].d;
        }
        sort(pro+1,pro+1+n,cmp);
        
        for(int i = 1;i <= n;i++){
            for(int j = pro[i].d - 1;j >= 0;j--){
                if(isfree[j] == 0){
                    isfree[j] = 1;
                    ans += pro[i].p;
                    break;
                }
            }
        }
        cout << ans << endl;
        memset(pro,0,sizeof(node)); 
        memset(isfree,0,sizeof(isfree));
    }
    return 0;
}

J - Supermarket相关推荐

  1. 基于位置服务的信息推送系统设计

    1.1  研究目的与意义 随着空间信息技术和网络技术的快速发展,普通的地图信息展示已经无法满足人们的需求.GIS(Geographic Information System)作为拥有处理和分析空间信息 ...

  2. nyoj 208 Supermarket(贪心)

    Supermarket 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 A supermarket has a set Prod of products on sale. ...

  3. CF815C Karen and Supermarket [树形DP]

    题目传送门 Karen and Supermarket On the way home, Karen decided to stop by the supermarket to buy some gr ...

  4. Supermarket

    Supermarket 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 A supermarket has a set Prod of products on sale. ...

  5. poj 1456 Supermarket (贪心, 并查集)

    链接: http://poj.org/problem?id=1456 题目: Description A supermarket has a set Prod of products on sale. ...

  6. Supermarket | 贪心

    Supermarket | 贪心 from poj 1456 from acwing 145 时间限制 :2s 内存限制:65M Description: A supermarket has a se ...

  7. DTOJ3489 可怜与超市(supermarket)

    DTOJ3489 可怜与超市(supermarket) 题目 题目描述 输入格式 输出格式 样例 样例输入1 样例输出1 样例输入2 样例输出2 数据范围与提示 题解 题目 题目描述 九条可怜有 b ...

  8. 树上背包 CF815C Karen and Supermarket

    CF815C Karen and Supermarket Description Karen有 b b b 美元,超市出售 N N N 种商品.第 i i i 件商品可以以 c i c_i ci​ 美 ...

  9. [分享]杰.德.爱华兹(中国)软件 J.D. Edwards 在零售业解决方案

    J.D. Edwards 公司简介 美国J.D. Edwards公司创建于1977年,是世界领先的企业资源管理软件的开发商.总部位于美国丹佛的克罗拉多州,在全球拥有5636名员工.在世界各地设有49个 ...

最新文章

  1. 云开发使用 got 的 get/post 传参请求示例代码
  2. CEO亲自写代码登上热榜,从零开始打造“裸金属”树莓派
  3. javascript数字千分位格式化
  4. 基于python的FFT频率和振幅处理
  5. 数学奥赛用不用计算机,报考自招必看!五大学科竞赛利弊详解,到底哪科最适合你?...
  6. python的pwntools工具的日常使用
  7. IE 8 HTML Parsing Error:Unable to modify the parent container element before the child element is...
  8. win7开机动画_分享win7开机画面修改方法
  9. 微信公众号发红包 php,php微信公众号开发之现金红包
  10. 一些很好的python自动化办公方案(待整理到readthedocs中)
  11. 做对的事情远比把事情做对重要得多
  12. go语言入门(转载自开源社区)
  13. 便利店“三方会战”,谁是最后赢家?
  14. 【Python】Scrapy爬虫介绍requests爬虫移植到Scrapy爬虫
  15. fNIRS | 非平稳波形的预处理方法
  16. 《Unity 5.x游戏开发实战》一1.9 添加一个水平面
  17. 设置centos7.3的YUM源为国内阿里云源
  18. 电影《战狼2》的可视化分析
  19. 计算机组成原理第七章笔记---输入输出
  20. 120帧手机动态壁纸_小英雄高清动态壁纸app下载-小英雄高清动态壁纸v2.6手机下载...

热门文章

  1. 判断ip是固定ip地址还是动态ip
  2. 当选改革先锋,马baba的“数字经济”是什么
  3. 当无线通信正式成为战略能源:5G时代的蝴蝶振翅
  4. 获取url地址的方法
  5. meizz(梅花雪) 的个性化书签
  6. 【求1000以内的完数】Java实现计算1000以内的
  7. HostEase虚拟主机融合先进科技 全面提升产品核心竞争力
  8. 【redash】redash问题整理全(登录、查询)
  9. 设计师、游戏建模师电脑配置推荐,史上最全的配置单
  10. 在Arduino集成开发环境下使用ESP32WIFI和蓝牙遇到的问题