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
#include <cstdlib>#include<cstdio>#include<iostream>#include<cstring>using namespacestd;BOOLroad[ One][ One] = {false};intMain () {stringN; intT; CIN>>n>>u; intu,v; while(t--) {cin>>u>>v; ROAD[U][V]=true; } for(intk=0; k<=9;++k) for(intI=0; i<=9;++i) for(intj=0; j<=9;++j)if(k!=i&&i!=j&&k!=j)if(Road[i][k]&&road[k][j]) road[i][j]=true; Long Longsum=1; for(intI=0; I<n.length (); + +i) {intprenum=n[i]- -, changes=1; for(intj=0; j<=9;++j)if(ROAD[PRENUM][J]&&PRENUM!=J) + +changes; Sum*=changes; }cout<<sum<<Endl;return 0;}
Codevs 1009 Generating Number