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. CodeForces 70

    题目 A题 #include<bits/stdc++.h> using namespace std; int n,b,sum; int main(){ scanf("%d&quo ...

  2. Zookeeper与Curator二三事【坑爹】

    起因:我的Dubbo服务起不来:我本地Zookeeper3.4.11,Curator4.1 Caused by: org.apache.zookeeper.KeeperException$Unimpl ...

  3. 搭建vsf

    参考: 1.https://blog.csdn.net/liuzhenwen/article/details/7026263 我是全部替换了/lib/为/lib64/ 2.https://blog.c ...

  4. bootstrap浅谈

    学习地址:http://www.runoob.com/bootstrap/bootstrap-tutorial.html 自己练习了下 主要是使用了bootstrap中包含的class类样式,只要给相 ...

  5. openstack项目【day23】:glance基础

    本节内容 一 什么是glance 二 为何要有glance 三 glance的功能 四 glance的两个版本 五 镜像的数据存放 六 镜像的访问权限 七 镜像及任务的各种状态 八 glance包含的 ...

  6. dpkg用管道批量删除deb

    dpkg -l |grep deepin|awk '{print $2}'|xargs sudo dpkg -P

  7. HBase读写的几种方式(一)java篇

    1.HBase读写的方式概况 主要分为: 纯Java API读写HBase的方式: Spark读写HBase的方式: Flink读写HBase的方式: HBase通过Phoenix读写的方式: 第一种 ...

  8. PyQt5之窗口类型

    [TOC] 注:原创不易,转载请务必注明原作者和出处,感谢支持! 一 写在开头 1.1 本文内容 本文的主要内容:PyQt中的窗口部件:QMainWindow,QWidget,QDialog. 上述三 ...

  9. XSS攻击常识及常见的XSS攻击脚本汇总

    一.什么是XSS? XSS全称是Cross Site Scripting即跨站脚本,当目标网站目标用户浏览器渲染HTML文档的过程中,出现了不被预期的脚本指令并执行时,XSS就发生了. 这里我们主要注 ...

  10. django发送邮件send_mail&send_mass_mail

    一.配置 在setting.py中进行相关配置: EMAIL_HOST = 'smtp.sina.cn' #SMTP地址 EMAIL_PORT = 25 #SMTP端口 EMAIL_HOST_USER ...