zoukankan      html  css  js  c++  java
  • UVA 10624 Super Number

    UVA_10624

        由于一开始直接回溯超时了,所以对部分数据进行了打表。

    #include<stdio.h>
    #include
    <string.h>
    int m,n,a[35];
    int dfs(int cur)
    {
    int i,j,s,c;
    if(cur==m)
    return 1;
    if(cur==0)
    {
    if(n==1)
    {
    for(i=n;i<10;i+=n)
    {
    a[cur]
    =i;
    if(dfs(cur+1))
    return 1;
    }
    }
    else
    for(i=1;i<10;i++)
    {
    a[cur]
    =i;
    if(dfs(cur+1))
    return 1;
    }
    }
    else if(cur>=n-1)
    {
    for(i=0;i<10;i++)
    {
    a[cur]
    =i;
    c
    =0;
    for(j=0;j<=cur;j++)
    {
    s
    =c*10+a[j];
    c
    =s%(cur+1);
    }
    if(c==0&&dfs(cur+1))
    return 1;
    }
    }
    else
    for(i=0;i<10;i++)
    {
    a[cur]
    =i;
    if(dfs(cur+1))
    return 1;
    }
    return 0;
    }
    int main()
    {
    int i,j,k,t,tt;
    scanf(
    "%d",&t);
    for(tt=0;tt<t;tt++)
    {
    scanf(
    "%d%d",&n,&m);
    printf(
    "Case %d: ",tt+1);
    if(m==29)
    if(n>=1&&n<=12)
    {
    if(n>=1&&n<=5)
    printf(
    "-1\n");
    else
    switch(n)
    {
    case 6:printf("39208896001212006680167258804\n");break;
    case 7:printf("18555536703606084000060008482\n");break;
    case 8:printf("10211576408418088880443254681\n");break;
    case 9:printf("10101279606082569080443254680\n");break;
    case 10:printf("10015192000842085860660000924\n");break;
    case 11:printf("10000351372830084060967250126\n");break;
    case 12:printf("10000028419290081060024006085\n");break;
    }
    continue;
    }
    memset(a,
    0,sizeof(a));
    if(dfs(0))
    {
    for(i=0;i<m;i++)
    printf(
    "%d",a[i]);
    }
    else
    printf(
    "-1");
    printf(
    "\n");
    }
    return 0;
    }


  • 相关阅读:
    poj3372 Candy Distribution
    poj3270 Cow Sorting
    poj2888 Magic Bracelet
    poj2429 GCD & LCM Inverse
    poj1811 Prime Test
    poj2689 Prime Distance
    【思维】2017多校训练七 HDU6121 Build a tree
    【字符串+BFS】Problem 7. James Bond
    【dfs】codeforces Journey
    【思维+贪心】codeforces Game of the Rows
  • 原文地址:https://www.cnblogs.com/staginner/p/2181779.html
Copyright © 2011-2022 走看看