zoukankan      html  css  js  c++  java
  • BZOJ2748(DP)

    非常简单的DP题。类似背包的操作,按照音量改变值进行状态转移即可。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define REP(i,n)                for(int i(0); i <  (n); ++i)
    #define rep(i,a,b)              for(int i(a); i <= (b); ++i)
    #define dec(i,a,b)              for(int i(a); i >= (b); --i)
    #define for_edge(i,x)           for(int i = H[x]; i; i = X[i])
    
    #define LL      long long
    #define ULL     unsigned long long
    #define MP      make_pair
    #define PB      push_back
    #define FI      first
    #define SE      second
    #define INF     1 << 30
    
    const int N     =    100000      +       10;
    const int M     =    10000       +       10;
    const int Q     =    1000        +       10;
    const int A     =    30          +       1;
    
    int a[N];
    int f[A << 1][Q];
    int n, init, up;
    int x, ans;
    
    int main(){
    #ifndef ONLINE_JUDGE
    	freopen("test.txt", "r", stdin);
    	freopen("test.out", "w", stdout);
    #endif
    
    	memset(f, 0, sizeof f);
    	scanf("%d%d%d", &n, &init, &up);
    	rep(i, 1, n) scanf("%d", a + i);
    	f[0][init] = 1;
    	rep(i, 1, 50){
    		rep(j, 0, up){
    			x = j + a[i];
    			if (x >= 0 && x <= up) f[i][j] |= f[i - 1][x];
    			x = j - a[i];
    			if (x >= 0 && x <= up) f[i][j] |= f[i - 1][x];
    		}
    	}
    
    	ans = -1;
    	dec(i, up, 0){
    		if (f[n][i]){
    			ans = i;
    			break;
    		}
    	}
    /*
    	rep(i, 0, n){
    		rep(j, 0, up) printf("%d", f[i][j]);
    		putchar(10);
    	}
    */
    	printf("%d
    ", ans);
    
    	return 0;
    
    }
    
    
    


  • 相关阅读:
    jQuery的DOM操作
    jQuery的样式篇
    DOM对象控制HTML
    线程属性
    Glib动态加载模块(插件)
    linux 进程与线程命令
    error: server certificate verification failed.
    Qt qmake高级应用(翻译)
    Linux下设置QT环境变量
    pro、pri、prf、prl文件(qmake)
  • 原文地址:https://www.cnblogs.com/cxhscst2/p/6648802.html
Copyright © 2011-2022 走看看