1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <algorithm> #include <iostream> #include <limits> using namespace std; const int MAXN=105; const int MAXK=105; int h[MAXN][MAXK]; int f(int n, int m) { if(m==1)return n; if(n==0)return 0; int ret=numeric_limits<int>::max(); for (int i =1; i <=n; i++) ret=min(ret,max(f(n-i,m),f(i-1,m-1))+1); return ret; } int g(int n,int m){ for (int i =1; i <=n; i++) h[i][1]=i; for (int j =1; j <=m; j++) h[0][j]=0; for (int i = 1; i <=n; i++){ for (int j =2; j <=m; j++){ h[i][j]=numeric_limits<int>::max(); for(int k=1;k<=i;k++) h[i][j]=min(h[i][j],max(h[i-k][j],h[k-1][j-1])+1); } } return h[n][m]; } int main(){ int n,m; cin>>n>>m; cout<<f(n,m)<<endl<<g(n,m)<<endl<<endl; return 0; } |
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
22、当输入为“7 3”时,第 19 行用来取最小值的 min 函数执行了 449 次。( )
23. 输出的两行整数总是相同的。( )
24. 当m为1时,输出的第一行总为n。( )
25. 算法g(n,m)最为准确的时间复杂度分析结果为( )。
26、当输入为“20 2”时,输出的第一行为( )。
27. (4 分)当输入为“100 100”时,输出的第一行为()