Algorithm learning-with score and algorithm learning with score

Source: Internet
Author: User

Algorithm learning-with score and algorithm learning with score

Problem description
100 can be expressed as a score: 100 = 3 + 69258/714.

It can also be expressed as: 100 = 82 + 3546/197.

Note: The number must be 1 ~ 9 appears only once (excluding 0 ).

For example, 100 has 11 notation.

Input Format
Reads a positive integer N (N <1000*1000) from the standard input)

Output Format
The program outputs this number in digital 1 ~ 9. All types of data with scores are composed without repetition.

Note: you do not need to output each representation. Only the number of representations is counted!

Example input 1
100
Sample output 1
11
Sample input 2
105
Sample output 2
6

 

# Include <stdio. h> int w = 0, n, count = 0; int list [] = {1, 2, 4, 5, 6, 7, 8, 9}; int main () {void perm (int a [], int n, int k =-1); inline void Swap (int & a, int & B); int GetNum (int list [], int I, int j); scanf ("% d", & n); int temp = n; while (temp! = 0) {temp = temp/10; w ++;} perm (list, 9); printf ("% d \ n", count); return 0 ;} int GetNum (int list [], int I, int j) {// convert list [I] to list [j] into numbers int k, num = 0; for (k = I; k <= j; k ++) {num = num * 10 + list [k];} return num;} void perm (int a [], int size, int k =-1) {int I; if (k =-1) k = size-1; if (k = 0) {// The arrangement ends. Int j, u; // j indicates that the number of digits at the end of a cannot exceed the number of digits in num. The u table shows that the position of the bLast is int a = 0, B = 0, c = 0, bLast = 0; for (j = 0; j <w; j ++) {a = GetNum (list, 0, j ); /* num = a + B/c deformation can get B = (num-a) * c and cLast = list [8] can get bLast = (num-) * list [8]) % 10; */bLast = (n-a) * list [8]) % 10; for (u = j + 1; u <8; u ++) {if (list [u] = bLast) {B = GetNum (list, j + 1, u); c = GetNum (list, u + 1, 8 ); if (a + B/c = n & B % c = 0) count ++ ;}}} else {for (I = 0; I <= k; I ++) {int tmp; tmp = a [I]; a [I] = a [k]; a [k] = tmp; perm (a, size, k-1); tmp = a [I]; a [I] = a [k]; a [k] = tmp ;}}}

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.