⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saratov248.cpp

📁 My solutions to Saratov Online Judge Problems(SGU), not all, but many of them...
💻 CPP
字号:
/*
Alfonso2 Peterssen
15 - 5 - 2008
Saratov #248 "Integer Linear Programming" -> I don't think so
*/
#include <cstdio>
#include <algorithm>

using std::fill;

const int
    MAXV = 1000001,
    MAXN = 3,
    oo = 1 << 30;

int V, N;
int i, j;
int c[MAXN];
int dp[MAXV];

int main() {

    scanf( "%d", &N );
    for ( i = 0; i < N; i++ )
        scanf( "%d", &c[i] );
    scanf( "%d", &V );

    fill( dp + 1, dp + V + 1, oo );
    for ( i = 0; i < N; i++ )
        for ( j = c[i]; j <= V; j++ )
            dp[j] <?= dp[j - c[i]] + 1;

    if ( dp[V] == oo )
         printf( "-1\n" );
    else printf( "%d\n", dp[V] );

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -