核電站問題 |
Time Limit: 1 Seconds Memory Limit: 32768 K Total Submit:510 Accepted:112 |
Description 一個核電站有N個放核物質的坑,坑排列在一條直線上。 Input 該題有多組測試數據,每組數據一行,兩個正整數N,M( 1<N≤50,2≤M≤5) Output 每組數據只輸出一個正整數S,表示方案總數。 Sample Input 4 3 0 0
Sample Output 13
Source |
Source: #include<iostream> using namespace std; int n,m; unsigned long long f(int i) { if(i<-1) return 0; else if(i<=0) return 1; else return 2*f(i-1)-f(i-1-m); } int main() { while(cin>>n>>m) cout<<f(n)<<endl; return 0; }
|