zoukankan      html  css  js  c++  java
  • cf1132E. Knapsack(搜索)

    题意

    题目链接

    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 << '
    ';}
    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;
    }
    
  • 相关阅读:
    IIS Express中添加MIME
    js立即执行函数IIFE(Immediatelyinvokedfunctionexpression)的几种写法
    笑话一则
    字符串操作类 NET代码积累之一
    UrlRewriter使用详解
    压缩和解压缩的方法 from Byte[]
    C#日期格式化
    JavaScript模拟进度条
    让visual studio 2005 自动为类加版权
    godaddy免费空间完美安装部署dedecms
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10481631.html
Copyright © 2011-2022 走看看