(动规/完全背包)Cut Ribbon-CF 189A

题意:完全背包,保证有解
代码:

#include
#include 
#include  
#include  
#include  
#include   
#include   
#include   
#include    
#include    
#include    
#include      
#include      
using namespace std;
#define P(a,b,c) make_pair(a,make_pair(b,c))
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
//#define INF 0x3f3f3f3f
typedef pair >pii;
typedef long long ll;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
const int INF=0x7f7f7f7f;
const int maxn = 1e5+5;
int maxx[maxn];

int main(){
    int n,v[10];
    scanf("%d%d%d%d", &n,&v[1],&v[2],&v[3]);
    rep(i,1,n)
    {  
        maxx[i] = -INF;  
    }  
    rep(i,1,n)//表示总长
        for (int j=1; j<=3; j++)//对应段长  
            if(i >= v[j])
            {    
                if (maxx[i] <= (maxx[i-v[j]] +1))  
                    maxx[i] = maxx[i-v[j]] +1;  
            }  
    printf("%d\n", maxx[n]);  
    return 0;
}

你可能感兴趣的:((动规/完全背包)Cut Ribbon-CF 189A)