心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
完全背包问题。
以下是我的代码:
#include<iostream>
#define maxn 107
#define maxm 17
#define inf 20000007
using namespace std;
long min(long a,long b){return (a<b?a:b);}

long n,w[maxm],c[maxm],d[maxn];

int main()
{
    
for(long i=1;i<=10;i++)
    {
        cin
>>c[i];
        w[i]
=i;
    }
    cin
>>n;
    
//  Input
    
    d[
0]=0;
    
for(long i=1;i<=n;i++)
        d[i]
=inf;
    
for(long i=1;i<=10;i++)
        
for(long j=w[i];j<=n;j++)
            d[j]
=min(d[j],d[j-w[i]]+c[i]);
    
//   DP
    
    cout
<<d[n]<<endl;
    
//  Output
return 0;
}
posted on 2010-10-18 15:16 lee1r 阅读(253) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:动态规划

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理