[Blue Bridge Cup] [Algorithm improves vip]3000 meter ranking forecast

Source: Internet
Author: User

Time limit: 1Sec memory limit: 128MB commit: 12 Resolution: 10

When the topic described the 3000-metre long run, onlookers were jubilant in predicting the final rankings. Because they come from different classes, they don't necessarily know all the players, so they evaluate the strength of some of the athletes they know, that is, a prediction of the relative rankings of some of the athletes, and tell the poor remaining monitor. Because of boredom, so they went to the group to play DotA. After the game they asked the monitor for the final ranking, but the monitor did not remember, only remember which of them the prediction is correct, which people's prediction is wrong. They want to know what the ranking of the game might be.

Data size and conventions
1< =n< =10, 2< =c< =n, 1< =m< = 10, guaranteed data is legal, and the answer may not be more than 20000 in number. For a ranking sequence, a prediction is correct when and only if the relative order of the predicted rank is a subsequence of the rank sequence. A prediction is wrong when and only if this prediction is incorrect. Enter the first line two integers n, m,n for the number of athletes, m for the number of onlookers party. Athlete number from 0 to n-1.
Next M-line, each behavior a spectator party's relative ranking forecast. The first number in each line C indicates the number of people he predicts, followed by a different number of C 0~n-1, indicating the relative rank of the athlete he predicts, and finally a number, 0 means the prediction is wrong and 1 is correct. Output the first row one number k for the number of possible rankings.
The following K line, each line a 0~n-1 arrangement, for a certain possible ranking, adjacent to the number of spaces separated by a space. All rankings are sequentially output in dictionary order. Sample input
Sample output
Here the ans[][] array was first set to ANS[MAXN][MAXN], I want to hammer my own, the title said is within 20000, I set to 20.
#include <cstdio>#include<Set>#include<iostream>#include<algorithm>using namespacestd;Const intMAXN = -;inta[maxn][maxn],b[maxn],ans[20001][maxn],cnt;Set<int>PRE[MAXN];intn,m;BOOLVIS[MAXN];voidDFS (intIndexintu) { if(index==N) { for(intI=1; i<=m;i++) { intyes=0; if(a[i][a[i][0]+1]==1)Continue; intk=1, t=0, c=a[i][0]; while(t!=N) {if(A[i][k]!=b[t]) t++; Elsek++,t++; if(k==c+1) {yes=1; Break; } } if(yes)return ; } CNT++; for(intI=0; i<n;i++) ans[cnt][i]=B[i]; return ; } for(intv=0; v<n;v++) { if(vis[v]==false) { intyes=1; for(intI=0; i<index;i++) { if(Pre[b[i]].find (v)!=pre[b[i]].end ()) yes=0; } if(yes) {Vis[v]=true; B[index]=v; DFS (Index+1, V); VIS[V]=false; } } }}intMainvoid) {cin>>n>>m; for(intI=1; i<=m;i++) {cin>>a[i][0]; for(intj=1; j<=a[i][0]+1; j + +) cin>>A[i][j]; if(a[i][a[i][0]+1]!=0) for(intj=1; j<=a[i][0];j++) { intu=a[i][j],v; for(intk=1; k<j;k++) {v=A[i][k]; Pre[u].insert (v); }}} DFS (0, One); cout<<cnt<<Endl; for(intI=1; i<=cnt;i++) { for(intj=0; j<n;j++) cout<<ans[i][j]<<" "; cout<<Endl; } return 0;}

[Blue Bridge Cup] [Algorithm improves vip]3000 meter ranking forecast

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.