wojiaocbj

hanoi4

Apr 19th, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. /*
  2.  Author: 曹北健
  3.  Result: AC Submission_id: 3381889
  4.  Created at: Thu Apr 15 2021 21:56:46 GMT+0800 (China Standard Time)
  5.  Problem_id: 4300   Time: 40    Memory: 2632
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <math.h>
  10. #define INF 1e120
  11. double hanoi4[320] = {0};
  12. void init(){
  13.     int i,x;
  14.     double min;
  15.     hanoi4[1] = 1;hanoi4[2] = 3;
  16.     for(i = 3;i <= 300;i++){
  17.         min = INF;
  18.         for(x = 1;x < i;x++){
  19.             double cur = 2 * hanoi4[x] + (pow(2,i - x) - 1);
  20.             if(cur < min){
  21.                 min = cur;
  22.             }
  23.             hanoi4[i] = min;
  24.         }
  25.        
  26.     }
  27. }
  28. int main(){
  29.     init();
  30.     int n;
  31.     while(~scanf("%d",&n)){
  32.         printf("%.0f\n",hanoi4[n]);
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment