首页 > 代码库 > CodeForces 740A Alyona and copybooks

CodeForces 740A Alyona and copybooks

完全背包。

直接做个背包容量为$100000$的完全背包,这样就可以避免繁琐的分类讨论了。

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<ctime>#include<iostream>using namespace std;typedef long long LL;const double pi=acos(-1.0);void File(){    freopen("D:\\in.txt","r",stdin);    freopen("D:\\out.txt","w",stdout);}template <class T>inline void read(T &x){    char c = getchar();    x = 0;    while(!isdigit(c)) c = getchar();    while(isdigit(c))    {        x = x * 10 + c - 0;        c = getchar();    }}long long n,a,b,c;long long x[110000];int main(){    cin>>n>>a>>b>>c;    for(int i=0;i<=100000;i++) x[i]=i*a;    for(int i=2;i<=100000;i++) x[i]=min(x[i],x[i-2]+b);    for(int i=3;i<=100000;i++) x[i]=min(x[i],x[i-3]+c);    long long ans=-1;    for(int i=0;i<=100000;i++)    {        if((n+i)%4==0)        {            if(ans==-1) ans=x[i];            else ans=min(ans,x[i]);        }    }    cout<<ans<<endl;    return 0;}

 

CodeForces 740A Alyona and copybooks