如果我使用一维顺次结构储存计算中的结果,在每次取结果的时候还要查找,耗费O(n)的时间,这样是否可行呢?
请有经验的前辈谈谈.
能帮我看看题当然是太好了.
感谢前辈.
这是题目:
The 2006 FIFA World Cup Final was held in Berlin, Germany on July 9th, 2006, with France against Italy. Both France and Italy are the conquerors of the European soccer field. Soccer fans from all over the world came to Berlin Olympic Stadium to celebrate this world's biggest soccer party. In front of the ticket booth outside the stadium, we observed something interesting:
The ticket for the final match costs $50. There are m fans in the line having only $50 bill and n fans having only $100 bill. The ticket booth does not hold any changes. Please calculate in how many ways can these (m+n) soccer fans all get their tickets without the ticket booth running out of changes.
Input
Every pair of data consists of two non-negative integers m, n(not exceed 300), separated by a space. The last line of the input is a line containing two zeros.
Output
For every pair of data, output the number of ways the fans could line up.
Sample Input
1 1
1 2
3 0
0 0
Sample Output
1
0
1
我一开始用递归写了一个,发现到了20,20就已经出不来了,改用回溯的也一样.
考虑到里面有大量重复的计算,我想用三维S(已有的$50数量),M,N来保存一个结果.
所以才在这里问这个.