http://www.dotcpp.com/oj/problem1004.html?sid=748195&lang=1#editor
找规律 当1<=i<=4 ,a[i]=i
当 i>=5 ,a[i]=a[i-2]+a[i-3]+a[i-4]
#include<iostream> using namespace std; int n; int a[60]; int main() { for (int i = 1; i <= 54; i++){ if (i <= 4) a[i] = i; else a[i] = a[i - 2] + a[i - 3] + a[i - 4]; } while (cin >> n,n){ cout << a[n] << endl; } return 0; }