網頁

2014年1月29日 星期三

UVa 10696 f91

想法:
  典型的DP題目,把需要遞迴計算的答案用陣列存起來即可。


#include <cstdio>
using namespace std;
int fn[101]={0};
int f91 (int N){
if (N > 100) return N-10;
if (fn[N] != 0) return fn[N];
fn[N] = f91(f91(N+11));
return fn[N];
}
int main()
{
int n;
while (scanf("%d",&n)){
if (!n) break;
printf("f91(%d) = %d\n",n,f91(n));
}
return 0;
}

沒有留言:

張貼留言