Background
Gives an integer n (n<10^30) and a K transform rule (k<=15).
Rules:
One number variable to another one number:
The right part of the rule cannot be zero.
For example: n=234. There are rules (k=2):
2-> 5
3-> 6
The integer 234 above can be transformed to produce an integer (including the original number):
234
534
264
564
A total of 4 different production numbers
Describe
Gives an integer n and a K rule.
Find out:
The number of different integers that can be generated after any transformation (0 or more times).
仅要求输出个数。
Format input Format
N k
X1 Y1
X2 y2
... ...
Xn yn
Output format
An integer (satisfies the number of conditions):
Example 1 sample input 1[copy]
234 22 53 6
Sample output 1[Copy]
4
Limit
1s per test point
Source
The third problem of noip2002 popularization group
----------------
A number can be transformed several times, Floyd the transitive closure (initialization d[i][i]=1), the multiplication principle updates the answer
To use high precision, pay attention to the output
////main.cpp//noip2002 Generation Number////Created by Candy on 9/10/16.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;typedef unsignedLong Longll;Const intn= -, b=1e4;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intK,x,y,d[n][n],f[n];CharS[n];voidFloyd () { for(intI=0; i<=9; i++) d[i][i]=1; for(intk=0; k<=9; k++) for(intI=0; i<=9; i++) for(intj=0; j<=9; j + +) D[i][j]=d[i][j]| | (d[i][k]&&D[k][j]); for(intI=0; i<=9; i++) for(intj=0; j<=9; j + +)if(D[i][j]) f[i]++;}structbig{intd[ -],size; Big () {size=1;}} ans;voidChengint (Big &a,intk) { intg=0, I; for(i=1; i<=a.size;i++){ inttmp=a.d[i]*K; A.d[i]= (tmp+g)%B; G= (tmp+g)/C; } while(g) {A.d[i++]=g%b; a.size++; G/=C; }}intMainintargcConst Char*argv[]) {scanf ("%s%d",s,&k); for(intI=1; i<=k;i++) scanf ("%d%d", &x,&y), d[x][y]=1; Floyd (); ans.d[1]=1; intlen=strlen (s); for(intI=0; i<len;i++){ inta=s[i]-'0'; Chengint (Ans,f[a]); //printf ("F%d%d\n", A,f[a]); } for(inti=ans.size;i>=1; i--){ if(i!=ans.size) { if(ans.d[i]<Ten) cout<<" the"; Else if(ans.d[i]< -) cout<<"xx"; Else if(ans.d[i]< +) cout<<"0"; } cout<<Ans.d[i]; } return 0;}
NOIP2002PJ generation Number [Floyd high accuracy]