Codevs 1009 Generating Number

Source: Internet
Author: User
Tags x2 y2

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]&AMP;&AMP;PRENUM!=J) + +changes; Sum*=changes; }cout<<sum<<Endl;return 0;}

Codevs 1009 Generating Number

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.