码迷,mamicode.com
首页 > 其他好文 > 详细

hdu1028 Ignatius and the Princess III

时间:2015-04-18 21:51:56      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1028

递归能跑。。。

但是我交了直接超时了,然后我就把数据跑出来了再交的,等的时间有点长(怪不得超时)。

过的有点猥琐,看别人代码用母函数过的。

 1 #include<iostream>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<stdlib.h>
 5 #include<stdio.h>
 6 using namespace std;
 7 int b[130];
 8 const int M=120;
 9 int divide(int n,int m)
10 {
11     if(n==1 || m==1)
12     return 1;
13     if(n==m)
14     return (divide(n,m-1)+1);
15     if(n>m)
16     return (divide(n,m-1)+divide(n-m,m));
17     if(n<m)
18     return divide(n,n);
19 }
20 void table()
21 {
22     memset(b,0,sizeof(b));
23     for(int i=1;i<=M;i++)
24     b[i]=divide(i,i);
25 }
26 
27 int main()
28 {
29     freopen("out2.txt","w",stdout);
30     int n;
31     table();
32     for(int i=1;i<=M;i++)
33     {
34         printf("%d,",b[i]);
35         if(i%10==0)
36         printf("\n");
37     }
38     return 0;
39 }

 

 

 1 #include<iostream>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<stdlib.h>
 5 #include<stdio.h>
 6 using namespace std;
 7 int b[130]={1,1,2,3,5,7,11,15,22,30,42,
 8 56,77,101,135,176,231,297,385,490,627,
 9 792,1002,1255,1575,1958,2436,3010,3718,4565,5604,
10 6842,8349,10143,12310,14883,17977,21637,26015,31185,37338,
11 44583,53174,63261,75175,89134,105558,124754,147273,173525,204226,
12 239943,281589,329931,386155,451276,526823,614154,715220,831820,966467,
13 1121505,1300156,1505499,1741630,2012558,2323520,2679689,3087735,3554345,
14 4087968,4697205,5392783,6185689,7089500,8118264,9289091,10619863,12132164,
15 13848650,15796476,18004327,20506255,23338469,26543660,30167357,34262962,
16 38887673,44108109,49995925,56634173,64112359,72533807,82010177,92669720,
17 104651419,118114304,133230930,150198136,169229875,190569292,
18 214481126,241265379,271248950,304801365,342325709,384276336,431149389,
19 483502844,541946240,607163746,679903203,761002156,851376628,952050665,
20 1064144451,1188908248,1327710076,1482074143,1653668665,1844349560};
21 int main()
22 {
23     int n;
24     while(~scanf("%d",&n))
25     {
26         printf("%d\n",b[n]);
27     }
28     return 0;
29 }

 

hdu1028 Ignatius and the Princess III

标签:

原文地址:http://www.cnblogs.com/xuesen1995/p/4438060.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!