zoukankan      html  css  js  c++  java
  • [POI2005]BAN-Bank Notes

    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define ll long long
    using namespace std;
    
    const int A = 1e7+10;
    const int B = 1e5+10;
    const int mod = 1e9 + 7;
    const int inf = 0x3f3f3f3f;
    
    inline int read() {
      char c = getchar();
      int x = 0, f = 1;
      for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
      for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
      return x * f;
    }
    
    int a[210],b[210],val[B],c[B],p[B],cnt,n,m,f[B],g[20007][211];
    
    int main()
    {
        n=read();
        int s=n;
        memset(f,63,sizeof(f));
        f[0]=0;
        for (int i=1;i<=n;i++) a[i]=read(),g[a[i]][i]=1;
        for (int i=1;i<=n;i++) b[i]=read();
        
        for (int i=1;i<=n;i++)
        {
            int r=1;
            while (b[i])
            {
                c[++cnt]=a[i]*r; val[cnt]=r; b[i]-=r;r<<=1; p[cnt]=i; 
                if (b[i] <= r)
                {
                    c[++cnt]=a[i]*b[i];
                    val[cnt]=b[i];
                    b[i]=0;
                    p[cnt]=i;
                }
            }
        }
        
        m=read();
        for (int i=1;i<=cnt;i++)
            for (int j=m;j>=c[i];j--)
                if(f[j-c[i]]+val[i]<f[j])
                {
                    memcpy(g[j],g[j-c[i]],sizeof (g[j-c[i]]));
                    f[j]=f[j-c[i]]+val[i];
                    g[j][p[i]]=g[j-c[i]][p[i]]+val[i];
                }
        
        printf("%d
    ",f[m]);
        //cout << n;
    //    for (int i=1;i<=n;i++) 
    //    {
    //        printf("%d ",g[m][i]);
    //    } 
    }
    
  • 相关阅读:
    xtu数据结构 I. A Simple Tree Problem
    图论trainning-part-1 A. 最短路
    xtu数据结构 D. Necklace
    xtu数据结构 G. Count the Colors
    xtu数据结构 B. Get Many Persimmon Trees
    xtu数据结构 C. Ultra-QuickSort
    NYOJ 118 修路方案
    POJ 1679 The Unique MST
    NYOJ 115 城市平乱
    NYOJ 38 布线问题
  • 原文地址:https://www.cnblogs.com/lToZvTe/p/14534081.html
Copyright © 2011-2022 走看看