Gym 100963B
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的更多相关文章
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- jatoolsprinter web打印控件直接打印不弹出
1.功能 主要是实现页面点击按钮,不弹窗,直接打印. 可以指定某个打印机打印 可以使用默认打印机打印 2.版本 主要有:免费版跟付费版 免费版官网:http://printfree.jatools.c ...
- 探索 Python 学习
Python 是一种敏捷的.动态类型化的.极富表现力的开源编程语言,可以被自由地安装到多种平台上(参阅 参考资料).Python 代码是被解释的.如果您对编辑.构建和执行循环较为熟悉,则 Python ...
- 用Spring构建企业Java应用程序的方法
https://mp.weixin.qq.com/s?__biz=MzU0MDEwMjgwNA==&mid=2247484965&idx=1&sn=ca6b847c65e506 ...
- 消息框MessageBox+遍历控件
消息对话框:主要用来显示信息,也可以警告.用户确认取消等. MessageBox.Show("展示内容","标题",MessageBoxButtons.按钮种类 ...
- BIOS翻译
BIOS翻译 BIOS(Basic Input/Output System—基本输入输出系统).BIOS可以视为是一个永久地记录在ROM中的一个软件 Main主要信息 :main 主要信息 advan ...
- Gradle(一)安装配置
Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建开源工具.它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,抛弃了基于XML的各种繁琐配置.面向 ...
- HTML(二)HTML元素(整体结构,块级元素,内联元素,结构元素,交互元素,元素嵌套规则)
HTML整体结构解释 <!DOCTYPE html> // 文件应以"<!DOCTYPE ......>"首行顶格开始,推荐使用"<!DOC ...
- ext.net单元格内容换行显示
增加style .x-grid3-cell-inner { white-space: normal; }
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or.....
1,<activity android:name=".DialogActivity" android:theme="@android:style/Theme.Dia ...
- spawn-fcgi启动的一些报错问题
spawn-fcgi启动报错 //编译生成bin文件,这里用到了fcgi和google的glog # g++ test.cpp -lfcgi -lglog -o test //运行 # spawn-f ...