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. POJ2516:Minimum Cost(最小费用最大流)

    Minimum Cost Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19088   Accepted: 6740 题目链 ...

  2. mysql__索引的设计和使用

    索引的设计和使用 1 索引概述 MySIAM和InnoDB存储引擎的表默认创建的都是BTREE索引,MySQL目前不支持函数索引,但是支持前缀索引.还支持全文本索引,但是只有MySIAM(5.0开始) ...

  3. Awk basic and practice

    定义:Awk是一种程序语言,用来处理数据和产生报告.数据可来自标准输入,文件,管道输出. 格式:#awk '/pattern/ {action}' filename 术语:pattern, 样式是由正 ...

  4. eclipse 主题文件配置

    eclipse市场搜索 Eclipse Color Theme ----用于控制文本域主题 Eclipse 4 Chrome Theme  chrome风格的主题 最新的:Jeeeyul's Them ...

  5. html中offsetTop、clientTop、scrollTop、offsetTop各属性介绍(转载)

    HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度. scrollLeft: 设置或获取位于 ...

  6. HDU5748---(记录每个元素的 最长上升子序列 nlogn)

    分析: 给一个序列,求出每个位置结尾的最长上升子序列 O(n^2) 超时 #include "cstdio" #include "algorithm" #def ...

  7. 基于多线程的TCP socket通信经典案例

    服务器端 package com.thinkvenus.study.socket; import java.io.BufferedReader; import java.io.IOException; ...

  8. A way escape rbash

    hacker@beta:~$ ls -rbash: /usr/bin/python: restricted: cannot specify `/' in command names ryuu@beta ...

  9. efi转bios详细说明

    前言 制作好的efi格式的ubuntu15.10系统放到服务器主板上启动不了,于是将其改为bios格式,发现问题解决了,成功登入系统.下面是操作过程的一个记录. 测试环境 目标环境 系统: Ubunt ...

  10. (五)对linux内核中jiffies+Hz表示一秒钟的理解

    jiffies在内核中是一个全局变量,它用来统计系统启动以来系统中产生的总节拍数,这个变量定义在include/Linux/jiffies.h中,定义形式如下. unsigned long volat ...