zoukankan      html  css  js  c++  java
  • NYOJ 17 单调递增最长子序列

    链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=17

    经典的DP问题 。

    #include <iostream>
    #include <string.h>
    #define max(a,b) ((a) > (b) ? (a) : (b));
    using namespace std;
    char str[10000];
    int dp[10000];
    int main()
    {
    	int n;
    	cin>>n;
    	int i;
    	int j;
    	int ans;
    	while(n--)
    	{
    		cin>>str;
    		for(i=0;i<strlen(str);i++)				//初始化
    			dp[i]=1;
    		ans=0;
    		for (i=0;i<strlen(str);i++)
    		{
    			for (j=0;j<i;j++)
    			{
    				if(str[i]>str[j])					//DP方程
    					dp[i]=max(dp[j]+1,dp[i]);
    
    			}
    		}
    		for(i=0;i<strlen(str);i++)
    			if(ans<dp[i])
    				ans=dp[i];
    		cout<<ans<<endl;
    	}
    	return 0;
    }


     

  • 相关阅读:
    day11
    day10
    day9
    day8
    day7
    day6
    day14
    day13
    day12
    day11
  • 原文地址:https://www.cnblogs.com/frankM/p/4399550.html
Copyright © 2011-2022 走看看