Title Description
Description
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
Problem:
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).
Only the number of outputs is required.
Enter a description
Input Description
Keyboard sender, in the form of:
N k
X1 Y1
X2 y2
... ...
Xn yn
Output description
Output Description
Screen output in the form of:
An integer (satisfies the number of conditions)
Sample input
Sample Input
234 2
2 5
3 6
Sample output
Sample Output
4
Data range and Tips
Data Size & Hint
Exercises
High Precision +floyd.
Find the number that each number can evolve into (note there is a self) and multiply the number of each number in the sequence according to the multiplication principle.
var l,i,x,y,k,j:longint;
F:array[0..11,0..11]of Boolean;
Ans:array[0..11]of Longint;
A:array[0..1001]of Longint;
s:ansistring;
Begin
READLN (s);
Val (copy (S,pos (', s) +1,length (s)), k);
Delete (S,pos (", s), length (s));
L:=length (s);
For I:=1 to K do
Begin
Read (x, y);
F[x,y]:=true;
End
For k:=0 to 9 do
For i:=0 to 9 do
For j:=0 to 9 do f[i,j]:=f[i,j] or (I=J) or f[i,k] and f[k,j];
For i:=0 to 9 do
For j:=0 to 9 do Ans[i]:=ans[i]+ord (F[i,j]);
A[1]:=1;
A[0]:=1;
For I:=1 to L do
Begin
K:=ord (S[i])-48;
A[1]:=A[1]*ANS[K];
For j:=2 to A[0] do
Begin
A[j]:=a[j]*ans[k]+a[j-1]div 10;
A[J-1]:=A[J-1] MoD 10;
End
If A[a[0]]>9 Then
Begin
A[a[0]+1]:=a[a[0]] Div 10;
A[A[0]]:=A[A[0]] MoD 10;
Inc (A[0]);
End
End
For i:=a[0] Downto 1 do write (A[i]);
End.
2002 Generating Number