1962: 模型王子
Time Limit: 10 Sec Memory Limit: 64 MB
Description
Input
输入数据共一行,两个整数N,K,用一个空格隔开,具体意义如题目中所述。
Output
输出数据共一行,为最少所需要的时间S。
Sample Input
5 3
Sample Output
5
HINT
对于全部的数据,1 < = K < = 100,1 < = N < = 10^5
思路:
龙凡《一类猜数问题的研究》
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
#define N 100010
using namespace std;
int dp[N][110];
int main() {
int n, k;
while( scanf("%d%d", &n, &k) != EOF) {
int ans = 0;
for(int i=2; ; i++){
for(int j=2; j<=k; j++){
dp[i][j] = max(dp[i-2][j] + dp[i-1][j-1], dp[i-1][j] + dp[i-2][j-2]) + 1;
if(dp[i][j] >= n){
ans = i; break;
}
}
if( ans ) break;
}
printf("%d\n", ans);
}
return 0;
}