求助啊............

编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 6428 KiB, score = 10
测试数据 #1: WrongAnswer, time = 15 ms, mem = 6428 KiB, score = 0
测试数据 #2: WrongAnswer, time = 15 ms, mem = 6432 KiB, score = 0
测试数据 #3: Accepted, time = 0 ms, mem = 6428 KiB, score = 10
测试数据 #4: WrongAnswer, time = 15 ms, mem = 6428 KiB, score = 0
测试数据 #5: Accepted, time = 15 ms, mem = 6428 KiB, score = 10
测试数据 #6: WrongAnswer, time = 15 ms, mem = 6432 KiB, score = 0
测试数据 #7: Accepted, time = 7 ms, mem = 6428 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 6428 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 6424 KiB, score = 10
WrongAnswer, time = 82 ms, mem = 6432 KiB, score = 60
代码

#include<iostream>
#include<cstdio>
#include<cstring>
int f[30][50001];
using namespace std;
int main()
{
int n,m,p[30],price[30];
int w[30];
memset(f,0,sizeof(f));
memset(p,0,sizeof(p));
memset(price,0,sizeof(price));
memset(w,0,sizeof(w));
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>price[i]>>p[i];
w[i]=price[i]*p[i];
}
for(int i=1;i<=m;i++)
{
for(int j=0;j<=n;j++)
{
if(j>=price[i])
{
f[m][j]=w[i];
}
}
}

for(int i=m-1;i>0;i--)
{
for(int j=0;j<=n;j++)
{
f[i][j]=f[i+1][j];
if(j>=price[i])
{
if((f[i+1][j-price[i]]+w[i])>f[i][j])
{
f[i][j]=f[i+1][j-price[i]]+w[i];
}
}
}
}

/*
for(int i=1;i<=m;i++)
{
for(int j=0;j<=n;j++)
{
cout<<f[i][j]<<" ";
}
cout<<endl;
}
*/

cout<<f[1][n]<<endl;
return 0;
}

1 条评论

  • @ 2014-11-12 17:42:52

    没事了,结果是初始化的问题,已ac!

  • 1

信息

ID
1317
难度
3
分类
动态规划 | 背包 点击显示
标签
递交数
6628
已通过
3339
通过率
50%
被复制
29
上传者