hdu-1342 Lotto

http://acm.hdu.edu.cn/showproblem.php?

pid=1342

题意:以升序的形式给定k个数。输出从中挑选6个数满足升序的全部情况。

思路:两个參数。第一个保存当前搜索的位置,第二个保存个数。

#include<cstdio>
#include<cstring>
int a[15],b[15],vis[15],k;
void dfs(int ans,int num)
{
    if(num==6)
    {
        for(int i=0;i<5;i++)
            printf("%d ",b[i]);
        printf("%d\n",b[5]);
        return;
    }
    for(int i=ans;i<k;i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            b[num]=a[i];
            dfs(i+1,num+1);
            vis[i]=0;
        }
    }
}

int main()
{
    int flag=0;
    while(scanf("%d",&k)!=EOF&&k)
    {
        for(int i=0;i<k;i++)
            scanf("%d",&a[i]);
        if(flag) printf("\n");
        else flag=1;
        memset(vis,0,sizeof(vis));
        dfs(0,0);
    }
    return 0;
}
时间: 2024-10-10 14:54:11

hdu-1342 Lotto的相关文章

HDU 1342 Lotto 【DFS】

Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1610    Accepted Submission(s): 792 Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49

DFS HDU 1342

很水的DFS Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1515    Accepted Submission(s): 752 Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2

hdu 1342.. 复习广搜 顺便练习一下一个脑残的格式

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 pl

hdoj 1342 Lotto【dfs】

Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1736    Accepted Submission(s): 854 Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49}

hdu 1342 记忆化深搜

Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1657    Accepted Submission(s): 811 Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49

hdu 1342(DFS)

Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2933    Accepted Submission(s): 1386 Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49

HDU 1342 Lotto-DFS

Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1663    Accepted Submission(s): 815 Problem Description In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49

HDU 3105 Fred&#39;s Lotto Tickets(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3105 Problem Description Fred likes to play the lotto. Whenever he does, he buys lots of tickets. Each ticket has 6 unique numbers in the range from 1 to 49, inclusive. Fred likes to ``Cover all his base

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12