hdu1028 Ignatius and the Princess III

题目地址: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 }
时间: 2024-12-10 14:15:27

hdu1028 Ignatius and the Princess III的相关文章

HDU1028 Ignatius and the Princess III 【母函数模板题】

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12521    Accepted Submission(s): 8838 Problem Description "Well, it seems the first problem is too easy. I will let

HDU1028 Ignatius and the Princess III 母函数

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25867    Accepted Submission(s): 17879 Problem Description "Well, it seems the first problem is too easy. I will let

HDU1028 Ignatius and the Princess III【母函数】【完全背包】

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1028 题目大意: 给定正整数N,定义N = a[1] + a[2] + a[3] + - + a[m],a[i] > 0,1 <= m <= N. 对于给定的正整数N,问:能够找出多少种这样的等式? 思路: 对于N = 4, 4 = 4: 4 = 3 + 1: 4 = 2 + 2: 4 = 2 + 1 + 1: 4 = 1 + 1 + 1 + 1. 共有5种.N=4时,结果就是5.其实就是

【母函数】hdu1028 Ignatius and the Princess III

大意是给你1个整数n,问你能拆成多少种正整数组合.比如4有5种: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + 1 + 1;  4 = 1 + 1 + 1 + 1; 然后就是母函数模板题--小于n的正整数每种都有无限多个可以取用. (1+x+x^2+...)(1+x^2+x^4+...)...(1+x^n+...) 答案就是x^n的系数. #include<cstdio> #include<cstring> using namespace std;

ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)

Description "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says. "The second problem is, given an positive integer N, we define an equation like this:   N=a[1]+a[2]+a[3]+...+a[m];   a

hdu 1028 Ignatius and the Princess III(母函数,完全背包)

http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分问题. 第一道母函数...母函数入门 小于等于n的整数共有n个,1,2......n,每个数都有无限多个,对于整数1,它所对应的母函数为(1+x+x^2+...+x^k+...),整数2对应的母函数为(1+x^2+X^4+...+x^(2*k)+...),整数3对应的母函数为(1+x^3+x^6+...+x^(3*k)+...),以此类推,直到整数n. 那么n的整数划分的个数就是这n个母函数乘积

hdu 1028 Ignatius and the Princess III 【整数划分】

Ignatius and the Princess III                                                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15730    Accepted Submission(

hdu 1028 Ignatius and the Princess III 简单dp

题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是dp[i][i].那么dp[i][j]=dp[i][j-1]+dp[i-j][i-j],dp[i][j-1]是累加1到j-1的结果,dp[i-j][i-j]表示的就是最大为j,然后i-j有多少种表达方式啦.因为i-j可能大于j,这与我们定义的j为最大值矛盾,所以要去掉大于j的那些值 /*******

HDU 1028 Ignatius and the Princess III(母函数)

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15794    Accepted Submission(s): 11138 Description "Well, it seems the first problem is too easy. I will let you kno