码迷,mamicode.com
首页 > 其他好文 > 详细

TYVJ1214

时间:2014-08-24 23:30:13      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   div   log   sp   

大水题,凑数
恰好装满的完全背包求最大最小价值
复习:完全背包从小到大枚举,恰好装满初始化要为无穷大正负分别考虑

 

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 #define INF  11111111
 6 using namespace std;
 7 const int maxn = 105;
 8 const int maxv = 10005;
 9 int dp[maxv],dp1[maxv];
10 int a[maxn];
11 int main()
12 {
13     int n,s;
14     cin>>n>>s;
15     for(int i = 1;i<=n;++i)cin>>a[i];
16     for(int i = 1;i<=s;++i){dp[i] = -INF;dp1[i] = INF;}
17     dp[0] = dp1[0] = 0;
18     for(int i = 1;i<=n;++i)
19         for(int j = a[i];j<=s;++j)
20         {
21             dp[j] = max(dp[j],dp[j-a[i]]+1);
22             dp1[j] = min(dp1[j],dp1[j-a[i]]+1);
23         }
24     printf("%d\n%d\n",dp1[s],dp[s]);
25     return 0;
26 }

 

TYVJ1214

标签:style   blog   color   os   io   for   div   log   sp   

原文地址:http://www.cnblogs.com/GJKACAC/p/3933706.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!