A magical recursive formula--turn from 2108

Source: Internet
Author: User

Brother Zhi-yuan found a magical recursive formula,

Some recursive topics can be seen as a triangular array, and the problem of the solution (N,n) to the number of paths, nonsense not to say, the code on the title

The following transfers from http://www.cnblogs.com/--ZHIYUAN/p/5971367.html

The little bunny's chessboard.

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9447 Accepted Submission (s): 4879


Problem Description Rabbit's uncle from the outside of the trip back to bring her a gift, the rabbit happy to run back to his room, opened a look is a chessboard, little rabbit disappointed. But not a few days found the board of fun. The shortest path from the starting point (0,0) to the end point (N,n) is C (2n,n), and now the rabbit wants to do so if it does not cross the diagonal (but can touch the grid point on the diagonal), how many paths are there? The rabbit thought for a long time did not think out, now want to ask you to help the rabbit to solve this problem, for you should not be difficult !

Input enters a number n (1<=n<=35) at a time, and when n equals-1 o'clock ends the input.

Output for each input data export path number, the specific format to see sample.

Sample input1312-1

Sample OUTPUT1 1 22 3 103 12 416024

Authorrabbit

SOURCE RPG Session Code:
1/*2It does not go through the diagonal is the path does not cross the diagonal meaning ah. Recursion to hit the table, you can cover the lower half of the checkerboard is only a partial level of the number of columns greater than or equal to the number of rows, so that each point (x, Y) can be (x-1,y), (x,y-1) pushed3Finally get half the results of the chessboard and multiply by 2.4*/5 #include <iostream>6 #include <cstdio>7 #include <cstring>8UsingNamespaceStd9LongLong a[40][40];10voidInit ()11{Memset (A,0,sizeof(a));13Forint i=1;i<37;i++)a[i][0]=1;15Forint i=1;i<37;i++)16{17Forint j=1;j<=i;j++)18{a[i][j]=a[i-1][j]+a[i][j-1];20}21st}22}23IntMain ()24{25int t=0N26Init ();27 while (scanf ( "%d1< Span style= "COLOR: #000000" >) 28  { 29 t++; printf ( "%d%d%lld\n2 }32 return 0;                 

How many grains of sand are there in the sand?

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3935 Accepted Submission (s): 2074


Problem Description November 2005, our school participated in the ACM/ICPC Asia Division Chengdu Station Competition, here, we obtained the historic breakthrough, although just a bronze medal, but the excitement of the moment of the award, perhaps will always be engraved in the hearts of our several people. I would like to take this opportunity to express my thanks to all the veteran players who have been training for the ACM Asia competition for nearly half a year.
In fact, in addition to the award, there is one thing in this competition that also let us remember deeply. It was the day of the race waiting for admission, heard a member of a school said: "There is a school English name is very interesting, called What Hangzhou Dianzi University". Haha, it seems that the English name of our school is very good, very attractive.
However, the development of the matter who did not expect, with the Hangzhou Electric English School name of this exposure, the impact of more and more, many people began to hang Electric English school name Research, and soon after even set up a special research institutions, called "HDU School Name Research Society." And it has been reported that-------------------more famous scientists have been diverted to study this issue specifically, academia called "Hangzhou electric Phenomenon". Many people have published research papers in internationally renowned journals, especially one of the most famous research reports written by Miss 宇, a Chinese Super woman scientist, published in science titled "Why is Hangzhou electric so red?" "The study found that Hangzhou Dianzi University This school name has a profound philosophical thinking and connotation, she also put forward a bold conjecture:" Suppose a string consists of M h and N d, scan the string from left to right, If the cumulative number of character H is always not less than the cumulative number of character D, then the total number of strings that satisfy the condition is just as much as the sand sands. ”
This is the famous "宇 conjecture" Today!
Although it has not been possible to mathematically prove the correctness of this conjecture, it is said that the United States, under the personal intervention of George W. Bush, has been using supercomputers to verify that the (1<=n<=m<=1000000000000) is correct. My god! What a great conjecture it is! Although we always said that 21st century belongs to China, but still do not want this day to come so early, proud ing ... + touched ing ...
Moved and proud, the problem also came, if the values of M and n are known, please calculate how much sand grains in the sand.

Ps:
1. The Chinese authorities are actively moving to declare the Nobel Prize for Miss 宇.
2, "宇 conjecture" mentioned in the "H" and "D" string is now known as "Hangzhou Electric string" ("Hangzhou Electric string" was recently a sale of mutton skewers registered trademark, now our school is actively contact buyout, said the seller's reserve price is 10 million euros, no discount, it seems unlikely, sigh ... )

Input data contains multiple test instances, each of which consists of two integers m and N, and M and n represent the number of H and D in the string, respectively. Since the microcomputer we are using is not comparable to the old-American supercomputer, the data range given by the topic is (1&LT;=N&LT;=M&LT;=20).

Output for each test instance, print out how many grains of sand are in the sand, and calculate the rules refer to "宇 conjecture", one row for each instance output.

Sample INPUT1 13 1

Sample Output13

Authorlcy

Source HDU 2006-4 Programming Contest

Code:

1//Heck, the recursive formula for these two questions is the same. Originally this problem wanted to use DFS to search but timed out, and then found that the data results and the same problem. You can think like this,2//The row h is represented by a column, D is represented by a row, and the number of columns is always greater than the number of rows, which translates into a half-grid array on the upper triangle, seeking the number of paths from the starting point to the target point.3 #include <iostream>4 #include <cstdio>5UsingNamespaceStd6IntN,m;7LongLong a[21][21st];8voidInit ()9{10Forint i=1;i<=20;i++)a[i][0]=1;12Forint i=1;i<=20;i++)13{14Forint j=1;j<=i;j++)15{a[i][j]=a[i-1][j]+a[i][j-1];17}18}19}20IntMain ()21 {22  init (); 23 while (scanf ( "%d%d ", &n,&m)!=eof) Span style= "COLOR: #008080" >24  {25 printf (" %lld\n26 }27 return 0;                 

How many Trees?

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3754 Accepted Submission (s): 2108


Problem Descriptiona Binary search tree is a binary tree with the root k such that any node v reachable from it left have Labe L (v) <label (k) and any node w reachable from it Right have label (W) > label (k). It is a search structure which can find a node with label x in O (n log n) average time, where n is the size of the tree (n Umber of vertices).

Given a number n, can you tell how many different binary search trees may is constructed with a set of numbers of size n s Uch that each element of the set would be associated to the label of exactly one node in a binary search tree?

Inputthe input would contain a number 1 <= I <= per line representing the number of elements of the set.

The output of you has to print a line in the output for each entry and the answer to the previous question.

Sample Input123

Sample Output125

Source UVA

Code:

1PackageLuzhiyuan;2ImportJava.util.Scanner;3ImportJava.math.BigInteger;4PublicClassJAVA1 {5PublicStaticvoidMain (string[] args) {6 BigInteger [][]a=New biginteger[102][102];7 BigInteger sta=biginteger.valueof (1);//Convert other forms into large integers8 BigInteger zeo=biginteger.valueof (0);9Forint i=0;i<=100;i++)10Forint j=0;j<=100;j++)One by one a[i][j]=zeo;//If you want to make the subsequent addition function available, you must assign an initial value to a large integer.12Forint i=1;i<=100;i++)a[i][0]=Sta14Forint i=1;i<=100;i++)15Forint j=1;j<=i;j++){ 16 a[i][j]=a[i][j].add (A[i-1][j]);  A[i][j]=a[i][j].add (A[i][j-1 }19 Scanner cin=new< Span style= "COLOR: #000000" > Scanner (system.in); 20 while (Cin.hasnext ()) { 21 int n=cin.nextint (); Span style= "COLOR: #008080" >22  System.out.println (A[n][n]);  }24 }25}              

There's also a big hole in the brain that uses this recursive method:

1001:buy the Ticket

Problem Description

The "Harry Potter and the Goblet of Fire" would be on show in the next few days. As a crazy fan of Harry Potter, you'll go to the cinema and has the first sight, won ' t you?

Suppose the cinema only have one ticket-office and the price for per-ticket are dollars. The queue for buying the tickets are consisted of M + N persons (m persons each have the 50-dollar bill and N persons E Ach only has the 100-dollar bill).

Now, the problem for are to calculate the number of different ways of the "the" and the buying process won ' t be stopped From the first person till the last person.

Note:initially the Ticket-office has no money.

The buying process is stopped on the occasion that the Ticket-office have no 50-dollar bill but the first person of th E queue only had the 100-dollar bill.

Input

The input file contains several test cases. Each test case was made up of Numbers:m and N. It is terminated by M = n = 0. Otherwise, M, N <=100.

Output

For each test case, first print the test number (counting from 1) and then output the number of different ways in Another line.

Sample Input

3 0

3 1

3 3

0 0

Sample Output

Test #1:

6

Test #2:

18

Test #3:

180

Source

HUANG, Ninghai

Think that the number of 50 yuan will always be greater than 100 yuan, so it is the sand with the problem of the same, see Spring elder brother ... (Escape ....)

A magical recursive formula--turn from 2108

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.