HDU
来源:互联网 发布:心理健康测试软件 编辑:程序博客网 时间:2024/06/06 00:56
In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to select a subset S containing k (k>6) of these 49 numbers, and then play several games with choosing numbers only from S. For example, for k=8 and S = {1,2,3,5,8,13,21,34} there are 28 possible games:1,2,3,5,8,13 1,2,3,5,8,13,1,2,3,5,8,21 1,2,3,5,8,21,1,2,3,5,8,34 1,2,3,5,8,34,1,2,3,5,13,21 1,2,3,5,13,21, ... 3,5,8,13,21,34 3,5,8,13,21,34.
Your job is to write a program that reads in the number k and the set S and then prints all possible games choosing numbers only from S.
Your job is to write a program that reads in the number k and the set S and then prints all possible games choosing numbers only from S.
7 1 2 3 4 5 6 78 1 2 3 5 8 13 21 340
1 2 3 4 5 61 2 3 4 5 71 2 3 4 6 71 2 3 5 6 71 2 4 5 6 71 3 4 5 6 72 3 4 5 6 71 2 3 5 8 131 2 3 5 8 211 2 3 5 8 341 2 3 5 13 211 2 3 5 13 341 2 3 5 21 341 2 3 8 13 211 2 3 8 13 341 2 3 8 21 341 2 3 13 21 341 2 5 8 13 211 2 5 8 13 341 2 5 8 21 341 2 5 13 21 341 2 8 13 21 341 3 5 8 13 211 3 5 8 13 341 3 5 8 21 341 3 5 13 21 341 3 8 13 21 341 5 8 13 21 342 3 5 8 13 212 3 5 8 13 342 3 5 8 21 342 3 5 13 21 342 3 8 13 21 342 5 8 13 21 343 5 8 13 21 34
#include<iostream>
#include<cstdio>#include<cstring>using namespace std;int n,a[15];int vis[15];void DFS(int num,int k) { int i; if(k==6) { int ii=0; for(i=0; i<n; i++) { if(vis[i]) { ii++; if(ii==6) printf("%d\n",a[i]); else printf("%d ",a[i]); } } return ; } for(i=num+1; i<n; i++) { vis[i]=1; DFS(i,k+1); vis[i]=0; }}int main() { int i,l; int kk=0; while(scanf("%d",&n) && n) { if(kk!=0) printf("\n"); for(i=0; i<n; i++) scanf("%d",&a[i]); for(i=0; i<=n-6; i++) { memset(vis,0,sizeof(vis)); vis[i]=1; DFS(i,1); } kk++; }}
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- js获取url参数
- IO—文件删除
- 汪国新院长、郑桂兰董事长、汪汀总经理受邀出席长江脉主题年会
- (一)SpannableString、SpannableStringBuilder的简单使用
- NG_ML_Cousera_Summary
- HDU
- 会新版3D电影《狼牙山五壮士》新闻发布在保定举行
- spring boot使用记录
- 蓝桥杯
- ubuntu安装opencv3
- Android仿IOS弹出框
- Android init进程(长文)
- 【一图流】_04_一张图看懂 Java Binder:AMS注册到ServiceManager流程
- HTML表格跨多行rowspan,跨多列colspan