题目链接

大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱。

思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了。

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int n,m,a[N],k;
struct uzi
{
int a,b;
bool operator <(const uzi & t)const{
return b>t.b;
}
}p[N];
LL dp[2033],s[N];
int main(){
ios::sync_with_stdio(false);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
for(int i=1;i<=m;i++)cin>>p[i].a>>p[i].b;
for(int i=1;i<=k;i++){
dp[i]=dp[i-1]+a[i];
for(int j=1;j<=m;j++){
if(p[j].a<=i){
int l=i-p[j].a;
dp[i]=min(dp[i],dp[i-p[j].a]+s[i]-s[l]+s[i-p[j].a]-s[i+p[j].b-p[j].a]);
}
}
}
cout<<dp[k]<<endl;
return 0;
}

Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)的更多相关文章

  1. Codeforces Round #552 (Div. 3) F. Shovels Shop (前缀和预处理+贪心+dp)

    题目:http://codeforces.com/contest/1154/problem/F 题意:给你n个商品,然后还有m个特价活动,你买满x件就把你当前的x件中最便宜的y件价格免费,问你买k件花 ...

  2. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  3. Codeforces Round #369 (Div. 2) C. Coloring Trees(dp)

    Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They ...

  4. Codeforces Round #245 (Div. 1) B. Working out (dp)

    题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...

  5. Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)

    题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...

  6. Codeforces Round #349 (Div. 2) C. Reberland Linguistics (DP)

    C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...

  7. Codeforces Round #369 (Div. 2) C. Coloring Trees (DP)

    C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  9. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

随机推荐

  1. How to Make Fibonacci Confusing

    前几天同事发了这么一段代码 (fn => (f => f(f))(f => fn(n => f(f)(n))) )(g => n => [1, 2].indexOf ...

  2. centos 网卡状态

    由于ifconfig命令没法看到网卡的一些状态, 以下有5种方法查看网卡状态,是否连通网线 1)# dmesg | grep eth.....e1000: eth0 NIC Link is Up 10 ...

  3. MongoDB索引基本操作

    一.简介 在MongoDB建立索引能提高查询效率,只需要扫描索引只存储的这个集合的一小部分,并只把这小部分加载到内存中,效率大大的提高,如果没有建立索引,在查询时,MongoDB必须执行全表扫描,在数 ...

  4. 基于令牌桶算法实现的SpringBoot分布式无锁限流插件

    本文档不会是最新的,最新的请看Github! 1.简介 基于令牌桶算法和漏桶算法实现的纳秒级分布式无锁限流插件,完美嵌入SpringBoot.SpringCloud应用,支持接口限流.方法限流.系统限 ...

  5. 记录nodejs的writeHead

    使用response.writeHead()时,如果第二个参数的值使用错误的字符时,会使整个页面被镶嵌在<pre></pre>中被传输过去. 例: response.write ...

  6. 【MySQL 读书笔记】当我们在执行更新语句的时候我们在做什么

    该篇其实重点涉及两个日志的使用和处理. 一个是 server 层的 binlog 一个是服务器层的 redolog. 首先还是根据主线来介绍当我们在执行更新语句的时候我们在做什么 Redo Log M ...

  7. servlet(5) HttpSession

    Servlet 提供的 HttpSession 接口,提供了一种跨多个页面请求或访问网站时识别用户以及存储有关用户信息的方式. Servlet 容器使用这个接口来创建一个 HTTP 客户端和 HTTP ...

  8. 微信小程序之模板的使用

    初步学习小程序模板,就把过程写一下了. 1.在app.json里面注册temlate/public,生成模板wxml,wxss等系列页面 2.注册模板 <1>无数据传参的模板 <te ...

  9. odoo10源码 windows环境安装

    odoo10-windows开发环境(源码安装) 安装node 下载地址 http://nodejs.cn/download/ 安装教程https://www.cnblogs.com/zhouyu20 ...

  10. [搬运] 将 Visual Studio 的代码片段导出到 VS Code

    原文 : A Visual Studio to Visual Studio Code Snippet Converter 作者 : Rick Strahl 译者 : 张蘅水 导语 和原文作者一样,水弟 ...