Topcoder SRM 413 (Div 2) 1000.InfiniteSequence
来源:互联网 发布:淘宝经营类目的优势 编辑:程序博客网 时间:2024/05/23 18:37
Problem Statement
NOTE: This problem statement contains subscripts that may not display properly if viewed outside of the applet.
Let's consider an infinite sequence A defined as follows:
- A0 = 1;
- Ai = A[i/p] + A[i/q] for all i >= 1, where [x] denotes the floor function of x. (see Notes)
Definition
Class:InfiniteSequenceMethod:calcParameters:long long, int, intReturns:long longMethod signature:long long calc(long long n, int p, int q)(be sure your method is public)Limits
Time limit (s):2.000Memory limit (MB):64Notes
-[x] denotes the floor function of x which returns the highest integer less than or equal to x. For example, [3.4] = 3, [0.6] = 0.Constraints
-n will be between 0 and 10^12, inclusive.-p and q will both be between 2 and 10^9, inclusive.Examples
0)0
2
3
Returns: 1A[0] = 1.1)
7
2
3
Returns: 7A[0] = 1;
A[1] = A[0] + A[0] = 2;
A[2] = A[1] + A[0] = 2 + 1 = 3;
A[3] = A[2] + A[1] = 3 + 2 = 5;
A[7] = A[3] + A[2] = 5 + 3 = 8.2)
10000000
3
3
Returns: 327683)
256
2
4
Returns: 894)
1
1000000
1000000
Returns: 2
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
My Solution
Just memory search
// BEGIN CUT HERE// END CUT HERE#line 5 "InfiniteSequence.cpp"#include <string>#include <vector>#include <map>//#include <cmath>using namespace std;class InfiniteSequence {public: map<long long, long long> d;long long calc(long long n, int p, int q) {if(n == 0) return d[0] = 1;d[n] = (d[n/p] != 0) ? d[n/p] : calc(n/p, p, q);return d[n] += (d[n/q] != 0) ? d[n/q] : calc(n/q, p, q);}};
Thank you!
0 0
- Topcoder SRM 413 (Div 2) 1000.InfiniteSequence
- Topcoder SRM 462 DIV 2
- topcoder srm 518 div 2
- TopCoder SRM 561 Div 2
- Topcoder SRM 565 Div.2
- Topcoder SRM 628 DIV 2
- TopCoder SRM 144 DIV 2
- TopCoder——SRM 516 DIV 2
- TopCoder——SRM 518 DIV 2
- TopCoder——SRM 519 DIV 2
- Topcoder SRM 505 Div 2 hard
- TopCoder——SRM 520 DIV 2
- TopCoder——SRM 521 DIV 2
- topcoder SRM div 2 level 1
- TopCoder SRM 634 Div.2[ABC]
- TopCoder SRM 633 Div.2 500 Jumping
- 【topcoder】 SRM 144 div 2 200
- 【topcoder SRM 702 DIV 2 250】TestTaking
- Error:Android Packager: [应用名] java.io.FileNotFoundException: G:\xxx\应用名.unaligned.apk (拒绝访问。)
- 一些球形包围盒,AABB包围盒,OBB包围盒的文章
- sort函数
- 网站会员整合ucenter 实现多站点同步登录方法
- 单链表实现约瑟夫环(JosephCircle)(C语言)
- Topcoder SRM 413 (Div 2) 1000.InfiniteSequence
- Swift-画虚线、虚线圆
- xshell入门使用教程
- android 高仿UC浏览器首页上拉面板效果
- eclipse 打jar包并混淆
- 小易的升级之路(16年网易校招)
- List<String>转换为Set<String>.
- VPN column: PPTP(1)--connecting process
- BZOJ1502: [NOI2005]月下柠檬树