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

[POJ 1722] SUBTRACT

时间:2018-07-22 19:22:09      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:streambuf   ace   lex   code   fstream   ==   max   turn   exce   

[题目链接]

         http://poj.org/problem?id=1722

[算法]

          DP

[代码]

         

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
const int V = 15000;
const int MAXN = 30000;

int i,j,N,T,tmp,k;
int a[110];
int pre[110][MAXN];
bool f[110][MAXN];
char op[110];

int main() 
{
        
        scanf("%d%d",&N,&T);
        for (i = 1; i <= N; i++) scanf("%d",&a[i]);
        f[2][a[1] - a[2] + V] = true;
        pre[2][a[1] - a[2] + V] = -;
        for (i = 2; i <= N; i++)
        {
                for (j = 0; j < MAXN; j++)
                {
                        if (f[i][j])
                        {
                                f[i + 1][j - a[i + 1]] = true;
                                pre[i + 1][j - a[i + 1]] = -;
                                f[i + 1][j + a[i + 1]] = true;
                                pre[i + 1][j + a[i + 1]] = +;        
                        }    
                }    
        }
        tmp = T + V;
        for (i = N; i >= 2; i--)
        {
                op[i] = pre[i][tmp];
                if (pre[i][tmp] == -) tmp += a[i];
                else tmp -= a[i];
        }
        for (i = 2; i <= N; i++)
        {
                if (op[i] == +) 
                {
                        printf("%d\n",i - 1 - k);
                        k++;
                }    
        }
        for (i = 2; i <= N; i++)
        {
                if (op[i] == -)
                        printf("1\n");
        }
        
        return 0;
    
}

 

[POJ 1722] SUBTRACT

标签:streambuf   ace   lex   code   fstream   ==   max   turn   exce   

原文地址:https://www.cnblogs.com/evenbao/p/9350970.html

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