题目链接

大意:给你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. Python基础之元组

    元组初识 元组的认识 首先,我们来认识一下元组: # 定义一个元组 uesr_tuple = ("zhangsan", "lisi", "wangwu ...

  2. jupyter notebook修改默认路径和浏览器

    1.jupyter notebook --generate-config 2.修改jupyter_notebook_config.py配置文件 3.修改默认路径: c.NotebookApp.note ...

  3. C: printf参数执行顺序与前置后置自增自减的影响

    起源: 今天在了解副作用side-effect的过程中,看到了下面的网页,把我带到了由printf引起的一系列问题,纠结了一整天,勉强弄懂. 第一个代码没什么好解释的.而第二个printf(" ...

  4. ArrayBlockingQueue源码分析

    ArrayBlockingQueue是一个基于数组实现的有界的阻塞队列. 属性 //底层存储元素的数组.为final说明一旦初始化,容量不可变,所以是有界的. final Object[] items ...

  5. SpringMVC实现文件下载时,请求路径中的扩展名被省略

    问题描述 问题是这样的,我写了一个DownloadController,用来处理下载请求,预期效果如下: 客户端浏览器在访问URL -->   http://localhost:8080/ssm ...

  6. 数据转换失败 java.math.BigDecimal cannot be cast to java.lang.String

    从接口获取到数据,在转换的时候出现错误:java.math.BigDecimal cannot be cast to java.lang.String 因为一开始用的是使用关键字进行强制转换,后来发现 ...

  7. PHP加密解密函数(带有效期,过了有效期也解不了)

    转的,原来应该是discuz中弄的 <?php //加解密函数 //此函数的厉害之处在于可以在指定时间内加密还原字符串,超时无法还原. //这样我们就可以拿此函数来做很多用途了,比如:单点登录的 ...

  8. P2801 教主的魔法(分块入门)

    两个月之前听yyr学长讲的分块,感觉是个很神奇的暴力,但到现在还是懵的一匹 #include<bits/stdc++.h> using namespace std; ; int belon ...

  9. String.Join Method

    Overloads Join(String, String[], Int32, Int32) Concatenates the specified elements of a string array ...

  10. poj-3177(无向图缩点)

    题意:给你n个点,m条边的无向联通图,问你最少增加几条边,使得这个图每对点至少有两条路径 解题思路:考虑每个环内的点必定有>=2条路径,所以先把这个无向图中的环去掉,用并查集缩环,然后剩下的图一 ...