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

cf1132E. Knapsack(搜索)

时间:2019-03-06 10:35:24      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:mod   代码   nap   using   现在   链接   force   air   clu   

题意

题目链接

Sol

看了state里面最短的代码。。感觉自己真是菜的一批。。直接爆搜居然可以过?。。但是现在还没终测所以可能会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;
}

cf1132E. Knapsack(搜索)

标签:mod   代码   nap   using   现在   链接   force   air   clu   

原文地址:https://www.cnblogs.com/zwfymqz/p/10481631.html

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