Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: 曹北健
- Result: AC Submission_id: 3381889
- Created at: Thu Apr 15 2021 21:56:46 GMT+0800 (China Standard Time)
- Problem_id: 4300 Time: 40 Memory: 2632
- */
- #include <stdio.h>
- #include <math.h>
- #define INF 1e120
- double hanoi4[320] = {0};
- void init(){
- int i,x;
- double min;
- hanoi4[1] = 1;hanoi4[2] = 3;
- for(i = 3;i <= 300;i++){
- min = INF;
- for(x = 1;x < i;x++){
- double cur = 2 * hanoi4[x] + (pow(2,i - x) - 1);
- if(cur < min){
- min = cur;
- }
- hanoi4[i] = min;
- }
- }
- }
- int main(){
- init();
- int n;
- while(~scanf("%d",&n)){
- printf("%.0f\n",hanoi4[n]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment