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
outputs description output
Description
Screen output in the form of:
An integer (satisfies the number of conditions)
sample input to
sample
234 2
2 5
3 6
Sample output Sample
outputs
4
Because only the total number of output scenarios is required, it is generally not a search. Then consider the diagram and DP.
You can think of each number as a node, calculate the connectivity of each number to the other nodes separately, and then use the multiplication principle to count the total number of scenarios.
Connectivity queries can be handled with Floyd transitive closures, which is plainly the case:
for (int k=0;k<=9;k++) {for (int. i=0;i<=9;i++) {for (int j=0;j<=9;j++) {a[i][j]=a[i][j]| | (A[i][k]&&a[k][j]);}}
(digression: So now the brackets start another line, originally written on the right.) )
Because the data in the ten 30 times, to use the high-precision.
There are two small problems with writing this code. One is the problem of = and = = (how long have you made this mistake), then there is, do not over-trust scanf performance, input format must pay attention to. Not really, CIN.
Note that the whole of the array references that paragraph, passing pointers.
Release code:
--Taoist Gu Yi, also startled antigen. The opening of the account does not see its place.
"Daily Learning", "Floyd transmission closure + high-precision" codevs1009 generating number