The path of Practice ~ Buckle to Ace 1910 recursive function

Source: Internet
Author: User

1910 Recursive Functions

time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description Description

For a recursive function w (A, B, c).


If a <= 0 or b <= 0 or C <= 0 returns the value 1.


If a > B > or C > 20 returns W (20,20,20).


If a < b and B < C return W (A, B, c? 1) + W (A, B, 1, c? 1)? W (A, B? 1, c),


In other cases, return W (a? 1, B, c) + W (a? 1, b? 1, C) + W (a? 1, B, c? 1)? W (a? 1, b-1, c-1)

This is a simple recursive function, but it may be problematic to implement.

Enter a description Input Description

There will be several lines. Three numbers per line, indicating a, B, C. and 1,? 1,? 1 ends

Output description Output Description

Output several lines, and note the spaces in the various.

Sample input Sample Input

1 1 1
2 2 2
-1-1-1

Sample output Sample Output

W (1, 1, 1) = 2
W (2, 2, 2) = 4

Data range and Tips Data Size & Hint

A, B, C <, Task < 11

Portal ->>

^

|

This problem uses the mathematical thinking is my hand (Chao) writes (xi).

#include <iostream>#include<cstdlib>using namespacestd;intWintAintBintc) {    if(a<=0|| b<=0|| c<=0)return 1; Else if(a> -|| B> -|| C> -)returnW -, -, -); Else if(a<=b| | a<=c) {intI=1;  for(intj=0; j<a;j++) I*=2; returni; }    Else returnW (A-1, B,c) +w (A-1, B-1, c) +w (A-1, b,c-1)-W (A1, B-1, C-1);}intMain () {inta[ One][3],i,j;  for(i=0;i< One; i++) {cin>>a[i][0]>>a[i][1]>>a[i][2]; if(a[i][0]==-1&&a[i][1]==-1&&a[i][2]==-1) Break; }        for(j=0; j<i;j++) cout<<"W ("<<a[j][0]<<", "<<a[j][1]<<", "<<a[j][2]<<") = "<<w (a[j][0],a[j][1],a[j][2]) <<Endl; return 0;}
Click to expand

The path of Practice ~ Buckle to Ace 1910 recursive function

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.