欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

cf1132E. Knapsack(搜索)

程序员文章站 2022-04-28 11:08:55
题意 "题目链接" Sol 看了status里面最短的代码。。感觉自己真是菜的一批。。直接爆搜居然可以过?。。但是现在还没终测所以可能会fst。。 cppp include define Pair pair define MP(x, y) make_pair(x, y) define fi firs ......

题意

题目链接

sol

看了status里面最短的代码。。感觉自己真是菜的一批。。直接爆搜居然可以过?。。但是现在还没终测所以可能会fst。。

#include<bits/stdc++.h> 
#define pair pair<int, int>
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long 
#define ll long long 
#define fin(x) {freopen(#x".in","r",stdin);}
#define fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
const double eps = 1e-9;
template <typename a, typename b> inline bool chmin(a &a, b b){if(a > b) {a = b; return 1;} return 0;}
template <typename a, typename b> inline bool chmax(a &a, b b){if(a < b) {a = b; return 1;} return 0;}
template <typename a, typename b> inline ll add(a x, b y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename a, typename b> inline void add2(a &x, b y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename a, typename b> inline ll mul(a x, b y) {return 1ll * x * y % mod;}
template <typename a, typename b> inline void mul2(a &x, b y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename a> inline void debug(a a){cout << a << '\n';}
template <typename a> inline ll sqr(a x){return 1ll * x * x;}
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int w, a[9], ans;
void dfs(int x, int now) {
    if(x == 9) {chmax(ans, now);return ;}
    for(int num = 9, v = min((w - now) / x, a[x]); num; num--, v--)
        dfs(x + 1, now + max((int)0, v * x));
}
signed main() {
    w = read();
    for(int i = 1; i <= 8; i++) a[i] = read();
    dfs(1, 0);
    cout << ans;
    return 0;
}