【BZOJ-1962】模型王子 DP 猜数问题
1962: 模型王子
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 116 Solved: 66
[Submit][Status][Discuss]
Description
![](http://www.lydsy.com/JudgeOnline/images/1962.jpg)
Input
输入数据共一行,两个整数N,K,用一个空格隔开,具体意义如题目中所述。
Output
输出数据共一行,为最少所需要的时间S。
Sample Input
5 3
Sample Output
5
HINT
对于全部的数据,1 < = K < = 100,1 < = N < = 10^5
Source
Solution
直接想这个问题确实不是很好想啊
还是看论文吧:《一类猜数问题的研究》
Code
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; #define MAXN 100010 #define MAXK 110 int N,K,f[MAXN][MAXK]; void DP() { for (int i=2; i<=N; i++) for (int j=2; j<=K; j++) { f[i][j]=max(f[i-1][j]+f[i-2][j-2],f[i-2][j]+f[i-1][j-1])+1; if (f[i][j]>=N) {printf("%d\n",i); return;} } } int main() { while (scanf("%d%d",&N,&K)!=EOF) DP(); return 0; }
——It's a lonely path. Don't make it any lonelier than it has to be.