苟……
啊不对走错片场了……
有一条河,左边一个石墩(A区)上有编号为1,2,3,4,…,n的n只诹访子,河中有k个荷叶(C区),
还有h个石墩(D区),右边有一个石墩(B区),如下图2—5所示。n只诹访子要过河(从左岸石墩A到右
岸石墩B),规则为:
(1)石墩上可以承受任意多只诹访子,荷叶只能承受一只青蛙(不论大小);
(2)诹访子可以:A→B(表示可以从A跳到B,下同),A→C,A→D,C→B,D→B,D→C,C→D;
(3)当一个石墩上有多只诹访子时,则上面的诹访子只能跳到比它大1号的诹访子上面。
你的任务是对于给出的h,k,计算并输出最多能有多少只诹访子可以根据以上规则顺利过河?
这题啊太暴力了(不
下面是老师给的题解的原话:
结论为:f(h,k)=2h(k+1)
从具体到一般,推导过程如下:
f(0,0)=1
f(0,k)=k+1; (如k=3时,有4只青蛙可以过河)
f(1,k)=2(k+1); (递推思想)
……
依此类推:f(2,k)=(2*(k+1))*2=22(k+1);
……
这个虽然不是很明白,但是可以写出代码来
1 #include<cstdio> 2 using namespace std; 3 int main() 4 { 5 int h,k,ans = 1; 6 scanf("%d%d",&h,&k); 7 for(int i = 0;i < h;i++) ans *= 2; 8 ans = ans * (k + 1); 9 printf("%d",ans); 10 return 0; 11 }
当然不是最简单的写法,快速幂都没用
啊听说这题固输可以ac?不得不说太暴力了(