Brief Introduction:

给你一些种类的硬币,用最少的硬币数表示X

求最小的使贪心算法错误的X

Algorithm:

一道论文题,《A Polynomial-time Algorithm for the Change-making Problem》

证明先挖个坑,以后再填

感性猜想,我们可以构建出这样一个算法:

对于一种币值A,我们找出一个略大于A仅用币值不小于B且小于A的货币表示的值X,使得贪心算法在使用A后要用更多零碎的货币

这样,只要枚举A、B,找出最小的这样的值即可。存在性问题论文中也有证明。

Code:

#include <bits/stdc++.h>

using namespace std;

int n,dat[],res=-;

int main()
{
cin >> n;
for(int i=;i<=n;i++) cin >> dat[i]; for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
{
int cnt1=,cnt2=,W=dat[i]-,t; for(int k=i+;k<=j;k++) //非贪心做法
cnt1+=(W/dat[k]),W%=dat[k]; t=W=dat[i]--W+dat[j];
for(int k=;k<=n;k++) //贪心做法
cnt2+=(W/dat[k]),W%=dat[k]; if(cnt1<cnt2 && (res==- || res>t)) res=t;
}
cout << res;
return ;
}

Review:

多看结论题

[Codeforces 10E] Greedy Change的更多相关文章

  1. Greedy Change

    Greedy Change time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. Codeforces 1132G Greedy Subsequences [线段树]

    洛谷 Codeforces 看到题解那么少就来发一篇吧-- 思路 看完题目一脸懵逼,感觉无从下手. 莫名其妙地想到笛卡尔树,但笛卡尔树好像并没有太大作用. 考虑把笛卡尔树改一下:每个点的父亲设为它的右 ...

  3. [cf10E]Greedy Change

    对于$w$的表示方案,可以用序列描述,即$x_{i}$表示第$i$种货币的数量 贪心策略得到的方案即是(对应序列)字典序最大的方案,并定义最优策略得到的方案为在最小化货币总数的基础上,(对应序列)字典 ...

  4. Codeforces Round #376 (Div. 2) C题 Socks(dsu+graphs+greedy)

    Socks Problem Description: Arseniy is already grown-up and independent. His mother decided to leave ...

  5. codeforces C. New Year Ratings Change 解题报告

    题目链接:http://codeforces.com/problemset/problem/379/C 题目意思:有n个users,每个user都有自己想升的rating.要解决的问题是给予每个人不同 ...

  6. Mass Change Queries Codeforces - 911G

    https://codeforces.com/contest/911/problem/G 没想到线段树合并还能这么搞.. 对每个权值建一个线段树(动态开点),如果权值为k的线段树上第i位为1,那么表示 ...

  7. Codeforces Round #598 (Div. 3) A. Payment Without Change 水题

    A. Payment Without Change You have a coins of value n and b coins of value 1. You always pay in exac ...

  8. Educational Codeforces Round 40 G. Castle Defense (二分+滑动数组+greedy)

    G. Castle Defense time limit per test 1.5 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces.472F.Design Tutorial: Change the Goal(构造 线性基 高斯消元)

    题目链接 \(Description\) 给定两个长为\(n\)的数组\(x_i,y_i\).每次你可以选定\(i,j\),令\(x_i=x_i\ \mathbb{xor}\ x_j\)(\(i,j\ ...

随机推荐

  1. 【BZOJ3038】上帝造题的七分钟2 线段树

    根据一个数六次√必死,我们可以打标记死了就不管他了,于是有贡献的操作复杂度为O(n*logn*6),然而我们还有由于盲目修改造成的多余代价我们把每次查询的区间分成三部分前全死,中残,后全死,对于中残, ...

  2. gcc用法小记

    By francis_hao    Feb 13,2017 概要 这里只列出了最常用的选项   选项解释 -c|-S|-E 启动gcc编译器时,它会顺序执行预处理.编译.汇编和连接(四个阶段的详细介绍 ...

  3. 如何最快地实现 ALTER TABLE

    如果您不了解ALTER TABLE的语法,可以先参考: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html 使用ALTER TABLE 可以 ...

  4. npm install 权限的问题

    用ctrl+r切换到对象的目录,以管理圆的身份执行 npm cache clean first. If that doesn’t fix things, take a look in %APPDATA ...

  5. JS表单验证优化

    var validate = (function(){ var messages = { isEmail : '输入正确格式邮箱', isPhoneNum : '输入正确手机号' }; var val ...

  6. es6+最佳入门实践(12)

    12.class基础用法和继承 12.1.class基础语法 在es5中,面向对象我们通常写成这样 function Person(name,age) { this.name = name; this ...

  7. USACO_1.1_Your_Ride_Is_Here_(字符串+水题)

    描述 http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=ride 给出两个由大写字母组成,长度不大于$6$的字符串. 将字符串中的各字母的字典 ...

  8. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  9. python2.7字典转换成json时中文字符串变成unicode的问题:

    参考:http://blog.csdn.net/u014431852/article/details/53058951 编码问题: python2.7字典转换成json时中文字符串变成unicode的 ...

  10. Linux内核学习之中断 中断本质【转】

    转自:http://www.linuxidc.com/Linux/2011-11/47657.htm [中断概述] 中断本质上是一种特殊的电信号,由硬件设备发向处理器.异常和中断的不同是异常在产生时必 ...