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

[POJ 1952] BUY LOW,BUY LOWER

时间:2018-07-22 14:04:28      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:fstream   lan   algo   lis   链接   +=   cti   exception   def   

[题目链接]

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

[算法]

        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;
#define MAXN 5010

int i,j,n,ans1,ans2;
int a[MAXN],f[MAXN],g[MAXN];

int main() 
{
        
        scanf("%d",&n);
        for (i = 1; i <= n; i++) 
        {
                scanf("%d",&a[i]);
                f[i] = g[i] = 1;
        }
        for (i = 1; i <= n; i++)
        {
                for (j = i - 1; j >= 1; j--)
                {
                        if (a[j] > a[i])
                        {
                                if (f[j] + 1 > f[i])
                                {
                                        f[i] = f[j] + 1;
                                        g[i] = g[j];    
                                }    else if (f[j] + 1 == f[i]) g[i] += g[j];
                        }    else if (a[i] == a[j])
                        {
                                if (f[i] == 1)
                                        g[i] = 0;
                                break;
                        }
                }    
        }
        for (i = 1; i <= n; i++)
        {
                if (f[i] > ans1)
                {
                        ans1 = f[i];
                        ans2 = g[i];    
                }    else if (f[i] == ans1) ans2 += g[i];
        }
        printf("%d %d\n",ans1,ans2);
        
        return 0;
    
}

 

[POJ 1952] BUY LOW,BUY LOWER

标签:fstream   lan   algo   lis   链接   +=   cti   exception   def   

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

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