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

[POI2005]BAN-Bank Notes

时间:2021-03-16 13:45:15      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:define   include   turn   printf   mes   cto   getch   clu   stream   

#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\n",f[m]);
    //cout << n;
//    for (int i=1;i<=n;i++) 
//    {
//        printf("%d ",g[m][i]);
//    } 
}

[POI2005]BAN-Bank Notes

标签:define   include   turn   printf   mes   cto   getch   clu   stream   

原文地址:https://www.cnblogs.com/lToZvTe/p/14534081.html

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