标签:des blog ar io os sp for java strong
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 445 Accepted Submission(s): 167
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<string> #include<algorithm> #include<queue> #include<vector> #include<set> using namespace std; int n,p,a[1010],cnt,len; bool flag; struct line { int num; int pos; }path[1010]; bool check(int x,int y) { for(int i=x;i<y;i++) { if(a[i]==a[y]) return false; } return true; } void dfs(int dep,int pos) { if(cnt>=p) return ; if(dep==len) { cnt++; flag=true; for(int i=0;i<len-1;i++) printf("%d ",path[i].num); printf("%d\n",path[len-1].num); return ; } for(int i=pos;i<n;i++) { if(dep==0||path[dep-1].num<=a[i]) { if(dep==0&&!check(0,i)) continue; if(dep!=0&&!check(path[dep-1].pos+1,i)) continue; path[dep].num=a[i]; path[dep].pos=i; dfs(dep+1,i+1); } } } int main() { while(scanf("%d%d",&n,&p)!=EOF) { cnt=0; for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { len=i; flag=false; dfs(0,0); if(!flag||cnt>=p) break; } printf("\n"); } return 0; }
标签:des blog ar io os sp for java strong
原文地址:http://www.cnblogs.com/a972290869/p/4166248.html