饭卡 HDU - 2546
原题链接
考察:01背包
这道题懵逼半天,看了大佬的代码终于懂了点
思路:
这道题是和购买顺序有关的,我们先拿出最贵的菜,同时余额拿出5元,在剩余的余额尽可能买总和贵的菜.买完最后余额拿出的5元再买最贵的菜,这就是正解了....
也因为这道题搞明白了点01背包的板子.f[i][j]表示在j余额条件下,前i个物品所能达到的最大价值.这道题如果设置f[i][j]==余额的话,表示的是在前i个菜,买前j余额在买后能达到的最小余额.属性值和j的含义重复给我搞懵了..果然还是太菜啊
#include iostream
#include cstdio
#include algorithm
#include cstring
using namespace std;
const int N = 1010;
int a[N],f[N];
int main()
{
int n,m;
while(scanf("%d",n)n)
{
memset(f,0,sizeof f);
for(int i=1;i=n;i++) scanf("%d",a[i]);
sort(a+1,a+n+1);
scanf("%d",m);
if(m5) { printf("%d\n",m); continue;}
m-=5;
for(int i=1;i=n-1;i++)
for(int j=m;j=a[i];j--)
{
f[j] = max(f[j],f[j-a[i]]+a[i]);
}
printf("%d\n",m+5-f[m]-a[n]);
}
return 0;
}
饭卡 HDU - 2546 相关文章
hdu3117 Fibonacci Numbers(数论+矩阵快速幂)
题目链接: 3117 ( Fibonacci Numbers ) 位数小于 \(8\) 的可以打表直接输出。 对于位数大于 \(8\) 的,直接用大数求 \(Fibonacci\) 的第 \(n\) 项会 \(TLE\) ,因此需分别求解前 \(4\) 位和后 \(4\) 位。 后 \(4\) 位直接矩阵快速幂取模即可,参见 poj3070
HDU4847(字符串匹配)
http://acm.hdu.edu.cn/showproblem.phppid=4847 题意: 给定一段文本,统计其中doge出现的次数 思路: 水题,kmp可以做,使用STL中的string更简单; 代码: #includeiostream#includestdio.h#includestdlib.h#includestring#includeiomanip#includealgorith
Visible Trees HDU - 2841
原题链接 考察:容斥原理 思路: 这道题就是 GCD HDU - 1695 的弱化版.把这道题翻译一下就是在(1,a)区间有多少个与(1,b)区间的数gcd=1 想出这个就可以解决了,如果a b都声明int型,相乘的时候我们不要忘记转化long long 1 #include iostream 2 #include algorith
hduOj1002遇到的知识总结
strlen:一个c/c++的库函数,就是计数函数,即从串头开始,然后到‘\0’为止,不计入'\0' 代码思路:从后往前诸位相加,将大数转化为字符串,然后采取进位,最终结果数比原数字串多一位 #includeiostream#includecstringusing namespace std;int main(){ char
GCD HDU - 1695
原题链接 考察:容斥原理+埃氏筛+质因数分解 思路: gcd(x,y) = k 等价于gcd(x/k,y/k) = 1.设 u = x/k,v= y/k.找出范围内u与v互质的对数. 这里可以用欧拉函数做,枚举1~d/k每一个数i.如果i在b/k范围内就是欧拉函数值,如果>b/k就是该欧拉函数值-b/k~i中与gcd(i,
hdu5392 Infoplane in Tina Town(LCM + 快速幂取模)
题目链接: hdu5392 ( Infoplane in Tina Town ) 说来惭愧,鄙人费了好些功夫才读懂题意。。 ?对第一个样例: \({1,2,3}\) 执行一次宏变为 \(1,3,2\) ,再执行一次宏变为 \(1,2,3\) 。执行两次宏后回到原序列,因此答案为 \(2\) 。 ?对第二个样例: \(1,2,3,4
Game of Taking Stones HDU - 5973
Game of Taking Stones HDU - 5973 题目大意 给你两堆石子,分别有\(x\),\(y\)个,可以同时在两堆里取相同个数,也可以只在一堆里取不小于\(1\)个的石子。 \(x,y10^{100}\) 解 首先,不考虑数据范围,这是个经典的威佐夫博弈, 先手输 只需满足如下式子即可
ACM----HDU-1241 dfs2
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerou
HDU 5861 Road 线段树
//HDU 5861 #includeiostream#includealgorithm#includevector#includecstringusing namespace std;#define inf 0x3f3f3f3fconst int maxn = 2e5+5;int minn[maxn2], maxx[maxn2]; //开启时间的左右区间 int val[maxn];void build(int i, int l, int r){ min
HDU 1166 敌兵布阵 树状数组
单点更新,区间询问 //树状数组 #includeiostream#includealgorithm#includecstringusing namespace std;const int maxn = 5e4+5;int a[maxn], c[maxn];int T, n, x, k, cnt;char s[10];int lowbit(int i){ return i(-i); }void update(int i, int k){while(