Codeforces Round #381 (Div. 2) B. Alyona and flowers(思维题目)
来源:互联网 发布:pe中如何查看mac地址 编辑:程序博客网 时间:2024/06/08 16:06
题目链接:http://codeforces.com/contest/740/problem/B
【中文题意】现有n朵花,给你m组l和r,分别代表n朵花的一个子序列的左端点的位置和右端点的位置。每朵花在子序列出现的次数*它本身的价值就是可以增加的价值。这m个子序列你可以选择0-m个。但是每个最多只能选一次。
问你能增加的最大的价值是多少。
【思路分析】既然是增加的话,那么要求计入的每个子序列可以增加的价值都为正数,然后搞一个优先队列,把每个子序列可以产生的价值压进去,然后再把正的加上就好了。其实可以不用优先队列,每一次算出来大于0的话加上就好了。这个题我处理了一下数据,把所有的数据都加了100,为了方便计数。
【AC代码】
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;#define N 10000000000#define LL long longint a[105],book[205],book2[205],book3[205];int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=n;i++) { scanf("%d",&a[i]); book[a[i]+100]++; } priority_queue<int>q; int l,r; for(int i=1;i<=m;i++) { for(int j=0;j<=200;j++) { book2[j]=0; book3[j]=1; } scanf("%d%d",&l,&r); for(int j=l;j<=r;j++) { book2[a[j]+100]++; book3[a[j]+100]=0; } int sum=0; for(int j=l;j<=r;j++) { if(book[a[j]+100]&&book2[a[j]+100]&&book3[a[j]+100]==0) { book3[a[j]+100]=1; //printf("++%d %d\n",a[j],book2[a[j]+100]); sum+=a[j]*book2[a[j]+100]; //printf("---%d\n",sum); } } //printf("%d***\n",sum); q.push(sum); } int re=0; while(!q.empty()) { int tt=q.top(); //printf("%d\n",tt); q.pop(); if(tt>0) { re+=tt; } } printf("%d\n",re); } return 0;}
0 0
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(思维题目)
- Codeforces#381(Div. 2) B.Alyona and flowers【思维+暴力】
- Codeforces Round #381 (Div. 2) B. Alyona and flowers
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(贪心 模拟)
- Codeforces Round #209 (Div. 2) B. Alyona and flowers
- Codeforces Round #381 (Div. 2) A. Alyona and flowers
- Codeforces Round #381 (Div. 2) A. Alyona and copybooks(思维)
- Codeforces Round #381 (Div. 2) C. Alyona and mex(思维)
- Codeforces Round #381 (Div. 2) C. Alyona and mex(思维)
- Codeforces Round #401(Div. 2)C. Alyona and Spreadsheet【思维】
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex【水题】
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
- Codeforces Round #261 (Div. 2)B. Pashmak and Flowers
- Codeforces Round #261 (Div. 2) B.Pashmak and Flowers
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers【水】
- 单一原则
- java实现二叉查找树
- zynq u-boot驱动串口打印乱码或者无打印
- DDR基础之Write_leveling简介
- windows下python3.5安装setuptools以及百度坐标系(bd-09)、火星坐标系(国测局坐标系、gcj02)、WGS84坐标系之间的坐标互转python实现以及python中exce
- Codeforces Round #381 (Div. 2) B. Alyona and flowers(思维题目)
- 解决浏览器记住密码输入框的问题
- Spring容器配置注入List集合对象属性
- Android--将Uri从file://改成content://
- Linux下which、whereis、locate、find 命令的区别
- mysql权限管理
- 新开始
- 专利查询网站(免费)
- ORA-00845 MEMORY_TARGET not supported on this system