Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
此题 数据 应该有问题!!!!!输入 0 的时候,输出必须是1抛开此题,输入 0 的时候应该是 0 但是加了上述条件却WA... 所以大家去掉上面的那个条件就好 送几行 菜鸟 递归代码: #include <iostream> using namespace std; const int Max = 31; int n; long data[Max]; long f(int n) { int i; long times = 0; if(n == 0) return 1; if(n == 2) return 3; if(data[n] > 0) return data[n]; times += 3 * f(n - 2); for(i = 4;n - i >= 0;i += 2) { times += 2 * f(n - i); } data[n] = times; return times; } int main() { int i; for(i = 0;i < Max;i++) { data[i] = -1; } while(cin >> n && n >= 0) { if(n % 2 != 0) { cout << 0 << endl; continue; } cout << f(n) << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator