博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj3312: [Usaco2013 Nov]No Change
阅读量:5296 次
发布时间:2019-06-14

本文共 2749 字,大约阅读时间需要 9 分钟。

题意:

K个硬币,要买N个物品。K<=16,N<=1e5

给定买的顺序,即按顺序必须是一路买过去,当选定买的东西物品序列后,付出钱后,货主是不会找零钱的。现希望买完所需要的东西后,留下的钱越多越好,如果不能完成购买任务,输出-1

=>K那么小。。。那么我们可以想到二进制枚举状态。。。然后转移。。。好像算不上状压dp吧。。。时间复杂度O(K2^Klogn)

#include
#include
#include
#include
using namespace std;#define rep(i,s,t) for(int i=s;i<=t;i++)#define dwn(i,s,t) for(int i=s;i>=t;i--)#define clr(x,c) memset(x,c,sizeof(x))int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-'0',c=getchar(); return x;}const int nmax=20;const int maxn=1e5+5;const int inf=0x7f7f7f7f;int a[nmax],b[maxn],dp[maxn],n,m,sm;int find(int x,int eo){ if(x==m) return 0; int l=x,r=m,ans=0,mid; while(l<=r){ mid=(l+r)>>1; if(b[mid]-b[x]<=eo) ans=mid,l=mid+1; else r=mid-1; } return ans-x;}int main(){ n=read(),m=read(),sm=0; rep(i,1,n) a[i]=read(),sm+=a[i]; rep(i,1,m) b[i]=read()+b[i-1]; int se=(1<

  

3312: [Usaco2013 Nov]No Change

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 177  Solved: 113
[][][]

Description

Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 <= K <= 16), each with value in the range 1..100,000,000. FJ would like to make a sequence of N purchases (1 <= N <= 100,000), where the ith purchase costs c(i) units of money (1 <= c(i) <= 10,000). As he makes this sequence of purchases, he can periodically stop and pay, with a single coin, for all the purchases made since his last payment (of course, the single coin he uses must be large enough to pay for all of these). Unfortunately, the vendors at the market are completely out of change, so whenever FJ uses a coin that is larger than the amount of money he owes, he sadly receives no changes in return! Please compute the maximum amount of money FJ can end up with after making his N purchases in sequence. Output -1 if it is impossible for FJ to make all of his purchases.

 

K个硬币,要买N个物品。

给定买的顺序,即按顺序必须是一路买过去,当选定买的东西物品序列后,付出钱后,货主是不会找零钱的。现希望买完所需要的东西后,留下的钱越多越好,如果不能完成购买任务,输出-1

Input

Line 1: Two integers, K and N.

* Lines 2..1+K: Each line contains the amount of money of one of FJ's coins.

* Lines 2+K..1+N+K: These N lines contain the costs of FJ's intended purchases. 

Output

* Line 1: The maximum amount of money FJ can end up with, or -1 if FJ cannot complete all of his purchases.

Sample Input

3 6
12
15
10
6
3
3
2
3
7
INPUT DETAILS: FJ has 3 coins of values 12, 15, and 10. He must make purchases in sequence of value 6, 3, 3, 2, 3, and 7.

Sample Output

12
OUTPUT DETAILS: FJ spends his 10-unit coin on the first two purchases, then the 15-unit coin on the remaining purchases. This leaves him with the 12-unit coin.

HINT

 

Source

转载于:https://www.cnblogs.com/fighting-to-the-end/p/6036553.html

你可能感兴趣的文章
ie6下使用min-height的方法
查看>>
解析ArcGis的字段计算器(二)——有玄机的要素Geometry属性,在属性表就能查出孔洞、多部件...
查看>>
c++ const enum #define
查看>>
初次来博客园
查看>>
Restful风格wcf调用2——增删改查
查看>>
最近使用asp.net时遇到 "运行时错误" 解决方案
查看>>
比例简化
查看>>
centos mysql 修改端口
查看>>
xcode4 设置调试错误信息小结
查看>>
asp.net 文件下载 支持断点续传
查看>>
angulaijs中的ng-upload-file与阿里云oss服务的结合,实现在浏览器端上传文件到阿里云(速度可以达到1.5M)...
查看>>
Android ViewPager滑动导航菜单
查看>>
50%记录的函数
查看>>
scala 13 抽象类 字段方法
查看>>
CF528D. Fuzzy Search [FFT]
查看>>
N皇后问题--递归回溯
查看>>
LeetCode Longest Increasing Path in a Matrix
查看>>
查看系统中断和中断绑核关系
查看>>
上周分工概述
查看>>
运算符优先级
查看>>