POJ1887
来源:互联网 发布:有没有免费的域名 编辑:程序博客网 时间:2024/05/17 09:07
题意描述:n个无重复的非负且不大于32767(short表示范围)的整数,求其最大的递减(非连续)子序列
子问题:设第K个数最大递减子序列为S(k),则S(k) = MAX { S(i) + 1 } ( k < i < n,A[i] < A[k]) 。
代码:
#include <iostream>
#include <string>
#include <vector>
/*
*value 整数值
*num 从此节点开始到数组末尾的最大递减子序列
*/
struct node
{
int value;
int num;
};
int main()
{
using namespace std;
int n = 0;
vector<node> li;
int count = 0;
while( true )
{
while( 1 )
{
cin>>n;
if( n == -1 )
break;
node t ={ n,-1};
li.push_back(t);
}
int len = li.size();
count ++;
li[len-1].num = 1;
int i;
/*
*逐步扩大子问题,最终 i = 0;为原问题
*/
for( i = len-2; i >= 0; i-- )
{
int tvalue = li[i].value;
int mnum = 0;
/*
*对每个规模为len-i的子问题,根据已知的规模小于len-i的子问题
*/
for( int j = i+1; j < len; j++ )
{
if( li[j].value <= tvalue && li[j].num >= mnum )
{
mnum = li[j].num;
}
}
li[i].num = mnum+1;
}
int max = 0;
for( i = 0; i < len; i++ )
{
if( li[i].num > max )
max = li[i].num;
}
li.clear();
cout<<"Test #"<<count<<":"<<"\n"<<" "<<"maximum possible interceptions: "<<max<<endl;
cout<<endl;
int t2;
cin>>t2;
if(t2==-1)
break;
node nt ={ t2,-1};
li.push_back(nt);
}
return 0;
}
- poj1887
- poj1887
- poj1887
- poj1887
- POJ1887
- poj1887
- POJ1887--Testing the CATCHER
- poj1887 Testing the CATCHER
- POJ1887 Testing the CATCHER
- POJ1887 Testing the CATCHER
- poj1887 Testing the CATCHER
- poj1887最长降子序列
- poj1887(最长递减子序列)
- poj1887(最长下降子序列)
- POJ1887 最长下降子序列
- POJ1887 Testing the CATCHER(lis)
- poj1887(最长下降子序列)
- poj1887——Testing the CATCHER
- PHP使用iconv函数遍历数组转换字符集
- IOS中info.plist文件的关键字描述
- iOS中堆和栈的区别
- OpenStack J版 Neutron-server服务加载与启动源码分析(一)
- SOJ 1028. Hanoi Tower Sequence
- POJ1887
- xml简介
- Android Volley完全解析(一),初识Volley的基本用法
- 二元树中找出何为某一值的所有路径 【微软面试100题 第四题】
- 你一无所知的CSS
- Trains
- CY-TIY物联网实验箱基础实验功能参数简介
- xcode6命令行打包ipa
- 应届生应聘软件开发岗位推荐书籍