Gym 100963B
啊,郁闷,就tm调小了一点范围就A了,就写dp和贪心比较一下,范围到最大值的二倍-1就好了
假设最大值的2倍以内能满足最优条件,当金额范围超过最大值2倍的时候;
至于为什么,还不清楚,再想想

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int n;
int f[];
int a[];
bool flag;
int cnt;
int greedy,dp; void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void clear(){
For(i,,){
f[i]=inf;
}
greedy=;
} int get1(int x){
int r=;
for(int i=n;i;i--){
r+=x/a[i];
x%=a[i];
}
return r;
} int get2(int x){
//f[0]=1;
For(i,,n)
For(j,a[i],x)
f[j]=min(f[j],f[j-a[i]]+);
return f[x];
} int main(){
while(cin>>n&&n!=){
For(i,,n)
in(a[i]);
if(a[]!=){
cout<<"Case #"<<++cnt<<": Cannot pay some amount"<<endl;
continue;
}
clear();
For(i,,a[n]*-){
greedy=get1(i);
dp=get2(i);
if(greedy!=dp){
cout<<"Case #"<<++cnt<<": Cannot use greedy algorithm"<<endl;
//cout<<i<<" "<<greedy<<" "<<dp<<endl;
break;
}
}
if(greedy!=dp) continue;
cout<<"Case #"<<++cnt<<": OK"<<endl;
}
return ;
}

Gym 100963B的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. [SCOI2015]小凸想跑步

    题目描述 小凸晚上喜欢到操场跑步,今天他跑完两圈之后,他玩起了这样一个游戏. 操场是个凸 n 边形, nn 个顶点按照逆时针从 0 ∼n−1 编号.现在小凸随机站在操场中的某个位置,标记为p点.将 p ...

  2. 2018ICPC青岛现场赛 重现训练

    先贴代码,以及简要题解. 和一个队友下午双排打了一下,队友光速签到,我签的J被嫌弃写得慢以及演员...然后我秒出了E了思路然而难以置信这么简单的思路当时才过了十几个,于是发现D.F不是太好做.最后交了 ...

  3. 监控MySQL|Redis|MongoDB的执行语句(go-sniffer)

    上节回顾:https://www.cnblogs.com/dotnetcrazy/p/9986873.html 以CentOS为例: 1.环境 PS:如果不需要Golang环境,可以编译后把执行文件c ...

  4. Lua语法基础(一)

    1. 注释 -- 单行注释 --[[ 多行注释 --]] 2. 运行方式     (1)交互式运行         命令行下 lua进入交互模式     (2)命令行运行         lua + ...

  5. 理解 Web 中的Session

    ===================================Session 工作原理是什么?===================================因为 http 协议是无状态 ...

  6. Gronwall型不等式

    Problem. Suppose $x(t)\in C[0,T]$, and satisfies $$\bex t\in [0,T]\ra 1\leq x(t)\leq C_1+C_2\int_0^t ...

  7. Jenkins 子业务日志拆分分析方法

    需求 Jenkins日志打印内容很长,或者并发编译导致,日志内容不容易查看. 对于具体业务失败, 开发者希望看到具体业务自身的日志内容. 解法 tee 命令能够保证, shell命令执行的内容,即往控 ...

  8. react+antdesign

    http://scaffold.ant.design/#/scaffolds/ng-alain http://scaffold.ant.design/#/scaffolds/react-redux-a ...

  9. CentOS安装VLC

    For EL7: rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm rpm - ...

  10. 非极大值抑制(NMS)

    转自:https://www.cnblogs.com/makefile/p/nms.html 概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的 ...