题目链接

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

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

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mp make_pair
  6. #define pb push_back
  7. using namespace std;
  8. LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
  9. LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
  10. 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;}
  11. const int N = 2e5 +11;
  12. int n,m,a[N],k;
  13. struct uzi
  14. {
  15. int a,b;
  16. bool operator <(const uzi & t)const{
  17. return b>t.b;
  18. }
  19. }p[N];
  20. LL dp[2033],s[N];
  21. int main(){
  22. ios::sync_with_stdio(false);
  23. cin>>n>>m>>k;
  24. for(int i=1;i<=n;i++)cin>>a[i];
  25. sort(a+1,a+1+n);
  26. for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
  27. for(int i=1;i<=m;i++)cin>>p[i].a>>p[i].b;
  28. for(int i=1;i<=k;i++){
  29. dp[i]=dp[i-1]+a[i];
  30. for(int j=1;j<=m;j++){
  31. if(p[j].a<=i){
  32. int l=i-p[j].a;
  33. 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]);
  34. }
  35. }
  36. }
  37. cout<<dp[k]<<endl;
  38. return 0;
  39. }

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. C#:对字符串的各种处理

    字符串截取 SubString OR Remove string str3 = "123abc456"; //str3 = str3.Substring(0, i); //从左边开 ...

  2. ASP.NET Core 下自定义权限验证

    效果图: 如果没有权限时,显示: 代码: public class AuthorizeAdminAttribute : TypeFilterAttribute { #region 字段 private ...

  3. Linux新手随手笔记1.2

    重定向 输入重定向:将命令输出结果写入一个文件或将一个文件内容导回到命令里面的这个过程叫做重定向 :标准(>) 输出重定向   :覆盖写入清空写入(>)/追加写入(>>) :错 ...

  4. Golang 入门 : 打造开发环境

    工欲善其事,必先利其器!在学习和使用 Golang 时如果有一款得心应手的 IDE,相信一定可以事半功倍.虽然很多 IDE 都提供了对 Golang 的支持,但真正好用的没几个.VSCode 算是不错 ...

  5. Photoshop实例视频教程

    Photoshop实例视频教程 2019/04/23 文件名 大小 复古街机风建筑效果图PS教程.mp4 6.63 MB 48.PS教程从零开始学——切片选择工具.mp4 20.90 MB PS教程- ...

  6. 制作自己cocoapods库

    https://www.cnblogs.com/czc-wjm/p/5958103.html 今天来讲一下cocoapods制作,网上教程很多,就不再讲理论,直接操作: 1.创建仓库: 2.将仓库克隆 ...

  7. java中的线程池原理

    写的不错,https://www.cnblogs.com/dongguacai/p/6030187.html

  8. 安装maven,并配置eclipse

    平台 ubuntu 18.04 + Java 8 下载并安装Maven 下载页面:http://maven.apache.org/download.cgi 我这里使用写博客是最新的版本3.6.1,选择 ...

  9. js检查身份证号是否正确

    转的,比较完善的验证身份证号的代码 /* check(ID)验证身份证号码 返回值:0 : "是正确的身份证号" 1 : "身份证校验不符合求和模11=1这个等式&quo ...

  10. celery 和 haystack

    celery  是分布式异步框架 haystack  是全文检索  只能在Django中用. 一.什么是celery?     ---->它是Python写的,所以只支持Python使用.但是消 ...