"Daily Learning", "Floyd transmission closure + high-precision" codevs1009 generating number

Source: Internet
Author: User

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

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.