2016SDAU编程练习二1025
来源:互联网 发布:徽商银行网络培训平台 编辑:程序博客网 时间:2024/06/08 02:48
Problem Description
Search is important in the acm algorithm. When you want to solve a problem by using the search method, try to cut is very important.<br>Now give you a number sequence, include n (<=100) integers, each integer not bigger than 2^31, you want to find the first P subsequences that is not decrease (if total subsequence W is smaller than P, than just give the first W subsequences). The order of subsequences is that: first order the length of the subsequence. Second order the subsequence by lexicographical. For example initial sequence 1 3 2 the total legal subsequences is 5. According to order is {1}; {2}; {3}; {1,2}; {1,3}. If you also can not understand , please see the sample carefully. <br>
Input
The input contains multiple test cases.<br>Each test case include, first two integers n, P. (1<n<=100, 1<p<=100000). <br>
Output
For each test case output the sequences according to the problem description. And at the end of each case follow a empty line.
Sample Input
3 5<br>1 3 2<br>3 6<br>1 3 2<br>4 100<br>1 2 3 2<br>
Sample Output
1<br>2<br>3<br>1 2<br>1 3<br><br>1<br>2<br>3<br>1 2<br>1 3<br><br>1<br>2<br>3<br>1 2<br>1 3<br>2 2<br>2 3<br>1 2 2<br>1 2 3<br><br><br><div style='font-family:Times New Roman;font-size:14px;background-color:F4FBFF;border:#B7CBFF 1px dashed;padding:6px'><div style='font-family:Arial;font-weight:bold;color:#7CA9ED;border-bottom:#B7CBFF 1px dashed'><i>Hint</i></div>Hint : You must make sure each subsequence in the subsequences is unique.</div>
Author
yifenfei
Source
奋斗的年代
题意:给一个数列,还是求递增子序列
思路:感觉和24差不多吧
感想:完全不想写了。。。
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct numberr
{
int number;
int postion;
};
bool cmp(const numberr &a,const numberr &b)
{
if(a.number!=b.number)
return a.number<b.number;
return a.postion<b.postion;
}
numberr b[1005];
int a[1005];
int n,p,cou,dep;
int c[1005];
int dfs(int nowdep,int pos,int rr)
{
if(nowdep==dep)
{
cou++;
for(int i=0;i<nowdep-1;i++)
{
cout<<c[i]<<" ";
}
cout<<c[nowdep-1]<<endl;
if(cou==p) return 1;
return 0;
}
int pre,flag=0;
for(int i=pos;i<=n;i++)
{
if(b[i].postion>rr)
{
if(!flag)
{
flag=1;
pre=b[i].number;
}
else if(pre==b[i].number) continue;
pre=b[i].number;
c[nowdep]=b[i].number;
if(dfs(nowdep+1,i+1,b[i].postion))
return 1;
}
}
return 0;
}
int main()
{
//freopen("r.txt","r",stdin);
while(cin>>n>>p)
{
for(int i=1;i<=n;i++)
{
cin>>b[i].number;
b[i].postion=i;
}
sort(b+1,b+n+1,cmp);
cou=0;
for(int i=1;i<n;i++)
{
dep=i;
if(dfs(0,1,0))break;
}
cout<<endl;
}
return 0;
}
- 2016SDAU编程练习二1025
- 2016SDAU编程练习二1001
- 2016SDAU编程练习二1002
- 2016SDAU编程练习二1003
- 2016SDAU编程练习二1004
- 2016SDAU编程练习二1005
- 2016SDAU编程练习二1006
- 2016SDAU编程练习二1007
- 2016SDAU编程练习二1008
- 2016SDAU编程练习二1009
- 2016SDAU编程练习二1013
- 2016SDAU编程练习二1014
- 2016SDAU编程练习二1017
- 2016SDAU编程练习二1019
- 2016SDAU编程练习二1010
- 2016SDAU编程练习二1011
- 2016SDAU编程练习二1012
- 2016SDAU编程练习二1015
- 面向对象三大特性——封装
- ScrollView嵌套ListView只显示一行
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- "围观"设计模式(2)--里氏替换原则(LSP,Liskov Substitution Principle)
- Android Studio 2.0+发布APK出现ExternalSystemException: String index out of range: -123错误
- 2016SDAU编程练习二1025
- "围观"设计模式(3)--依赖倒置原则(DIP,Dependence Inversion Principle)
- linux下安装apache(httpd-2.4.3版本)各种坑
- [BZOJ1013][JSOI2008]球形空间产生器sphere(高斯消元)
- 机器学习之K近邻
- "围观"设计模式(4)--接口隔离原则(ISP,Interface Segregation Principle)
- Apache配置多个监听端口和不同的网站目录的简单方法
- asp.net 可选可输入的dropdownlist
- knn python