[Informatics ausai yiben Tong] Part 3: Number of ex2_3produce queues,

Source: Internet
Author: User

[Informatics ausai yiben Tong] Part 3: Number of ex2_3produce queues,

Returns an integer n (n <= 2000) (the Code applies to n <= 10 ^ 31) and k Transformation Rules (k <= 15 ).

Rule: 1. One digit can be converted into another digit;

2. the number on the right of the rule cannot be zero.

  

BFS

 1 #include <stdio.h> 2 #include <string.h> 3 #define maxn 1000 4  5 char num[33]; 6 int len,q[maxn],Visited[11]; 7 long long ans = 1; 8  9 int main (){10 //    freopen ("produce.in","r",stdin);11 //    freopen ("produce.out","w",stdout); 12     13     int i,j,k;14     int K,x[16],y[16];15     16     scanf ("%s%d",num,&K);17     for (i = 1;i<=K;i++)18         scanf ("%d%d",x+i,y+i);19     len = strlen (num);    20         21     int head = 0,tail = 0,temp;22         23     for (j = 0;j<len;j++){24         temp = 1;25         memset (Visited,0,sizeof(Visited));26         q[++tail] = num[j]-'0';27         do{28             head++;29             for (i = 1;i<=K;i++){30                 if (q[head] == x[i] && Visited[y[i]] == 0){31                     q[++tail] = y[i];32                     temp++;            33                     Visited[x[i]] = 1;34                     Visited[y[i]] = 1;35                 }36                 37             }38         }while (head<tail);39         ans*=temp;40     }41     42     printf ("%lld",ans);43     44     return 0;45 }

 

Related Article

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.