您的位置:首页 > 其它

BZOJ 1962 模型王子 (猜数问题 dp)

2017-10-17 21:14 253 查看

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
[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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: