POJ 的测试**到哪能找上? 向这样的**评测系统,在哪找的题哇?

时间:2014.02.24 发布人:**nghi

POJ 的测试**到哪能找上? 向这样的**评测系统,在哪找的题哇?

已解决问题

谷歌**nghi用户在2014.02.24提交了关于“今日说法POJ 的测试**到哪能找上? 向这样的**评测系统,在哪找的题哇?”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-09-12T23:00:03。POJ1276wronganswer不知道哪出问题了,高手请教!
我代码:
#include<stdio.h>
#include<string.h>

intf[100001];

intmain()
{
intcash,n,nk,dk;

while(scanf("%d",&cash)!=EOF){
scanf("%d",&n);
memset(f,0,sizeof(f));
if(cash>0)
while(n--){
scanf("%d%d",&nk,&dk);
while(nk--){
for(inti=cash;i>=0;i--)
if(i>=dk&&f[i-dk]+dk>f[i]&&f[i-dk]+dk<=i)
f[i]=f[i-dk]+dk;
}
}
printf("%d\n",f[cash]);
}
return0;
}希望大家能够帮助她。

详细问题描述及疑问:POJ1276wronganswer不知道哪出问题了,高手请教!
我代码:
#include<stdio.h>
#include<string.h>

intf[100001];

intmain()
{
intcash,n,nk,dk;

while(scanf("%d",&cash)!=EOF){
scanf("%d",&n);
memset(f,0,sizeof(f));
if(cash>0)
while(n--){
scanf("%d%d",&nk,&dk);
while(nk--){
for(inti=cash;i>=0;i--)
if(i>=dk&&f[i-dk]+dk>f[i]&&f[i-dk]+dk<=i)
f[i]=f[i-dk]+dk;
}
}
printf("%d\n",f[cash]);
}
return0;
}期待您的答案,当代劳模,所有人都应该向你学习 !

希望以下的回答,能够帮助你。

第1个回答

用户名:sunson0518  

不说那么多,直接上反例:
7350
031010010501010
输入了以上那测试用例后再测其他任何例子都无效,不信你测测。
所以要把if(cash>0)改为if(cash>=0),测评的时候发现超时,所以问题不在用例,你的算法效率太低了。你要重新考虑算法。