zoukankan      html  css  js  c++  java
  • [POJ 1742] Coins

    [题目链接]

             http://poj.org/problem?id=1742

    [算法]

            动态规划 + 贪心

    [代码] 

             

    #include <algorithm>  
    #include <bitset>  
    #include <cctype>  
    #include <cerrno>  
    #include <clocale>  
    #include <cmath>  
    #include <complex>  
    #include <cstdio>  
    #include <cstdlib>  
    #include <cstring>  
    #include <ctime>  
    #include <deque>  
    #include <exception>  
    #include <fstream>  
    #include <functional>  
    #include <limits>  
    #include <list>  
    #include <map>  
    #include <iomanip>  
    #include <ios>  
    #include <iosfwd>  
    #include <iostream>  
    #include <istream>  
    #include <ostream>  
    #include <queue>  
    #include <set>  
    #include <sstream>  
    #include <stdexcept>  
    #include <streambuf>  
    #include <string>  
    #include <utility>  
    #include <vector>  
    #include <cwchar>  
    #include <cwctype>  
    #include <stack>  
    #include <limits.h> 
    using namespace std;
    #define MAXN 110
    #define MAXM 100010
    
    int i,j,n,m,cnt;
    int a[MAXN],c[MAXN],used[MAXM];
    bool f[MAXM];
    
    int main()
    {
        
        while (scanf("%d%d",&n,&m) && (n || m))
        {
            memset(f,false,sizeof(f));
            for (i = 1; i <= n; i++) scanf("%d",&a[i]);
            for (i = 1; i <= n; i++) scanf("%d",&c[i]);
            f[0] = true;
            for (i = 1; i <= n; i++)
            {
                for (j = 0; j <= m; j++) used[j] = 0;
                for (j = a[i]; j <= m; j++)
                {
                    if (!f[j] && f[j - a[i]] && used[j - a[i]] < c[i])
                    {
                        f[j] = true;
                        used[j] = used[j - a[i]] + 1;
                    }
                }
            }
            cnt = 0;
            for (i = 1; i <= m; i++)
            {
                if (f[i])
                    cnt++;
            }
            printf("%d
    ",cnt);
        }
    
        return 0;
    }
  • 相关阅读:
    win7下设置smtp的方法
    win7下怎么安装IIS
    python语法笔记(二)
    python语法笔记(一)
    python 的类变量和对象变量
    mysql使用笔记(四)
    mysql使用笔记(三)
    mysql使用笔记(二)
    windows下重新安装TCP/IP协议栈
    c++程序编码
  • 原文地址:https://www.cnblogs.com/evenbao/p/9327958.html
Copyright © 2011-2022 走看看