http://acm.fzu.edu.cn/problem.php?pid=1698 最大乘积
2012-12-05 14:18
351 查看
Problem Description
一个正整数一般可以分为几个互不相同的自然数的和,如3=1+2,4=1+3,5=1+4=2+3,6=1+5=2+4,…。
现在你的任务是将指定的正整数n分解成若干个互不相同的自然数的和,且使这些自然数的乘积最大。
只一个正整数n,(3<= n< 10000)。
第一行是分解方案,相邻的数之间用一个空格分开,并且按由小到大的顺序。第二行是最大的乘积
10
2 3 5
60
很典型的数分解:
代码如下:
一个正整数一般可以分为几个互不相同的自然数的和,如3=1+2,4=1+3,5=1+4=2+3,6=1+5=2+4,…。
现在你的任务是将指定的正整数n分解成若干个互不相同的自然数的和,且使这些自然数的乘积最大。
![](image/prodesc.gif)
Input
只一个正整数n,(3<= n< 10000)。
![](image/prodesc.gif)
Output
第一行是分解方案,相邻的数之间用一个空格分开,并且按由小到大的顺序。第二行是最大的乘积10
2 3 5
60
很典型的数分解:
代码如下:
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int f[550],a[500]; int main() { int n; while(~scanf("%d",&n)) { if(n == 3) printf("1 2\n%d\n",2); else if(n == 4) printf("1 3\n%d\n",3); else{ int sum = 0,v = 1; memset(f,0,sizeof(f)); for(int i = 2;i < 200;i ++) { sum += i; if(sum > n){sum -= i;break;} a[v ++] = i; } int ss = n - sum; while(ss --) { for(int i = 1;i < v;i ++) if(i == v - 1) a[i] ++; else if(a[i] + 1 < a[i + 1]) { a[i] ++; break; } } printf("%d",a[1]); for(int i = 2;i < v;i ++) printf(" %d",a[i]); printf("\n"); f[1] = 1; int s; for(int i = 1;i < v;i ++) { int c = 0; for(int j = 1;j < 550;j ++) { s = f[j] * a[i] + c; f[j] = s % 10; c = s / 10; } } int k; for(int i = 550;i >= 1;i --) if(f[i]) { k = i; break; } for(int i = k ;i >= 1;i --) printf("%d",f[i]); printf("\n"); } } return 0; }
相关文章推荐
- 最大连续子序列&&http://acm.hdu.edu.cn/showproblem.php?pid=1231
- Problem 1057 ab from http://acm.fzu.edu.cn/problem.php?pid=1057
- http://acm.hdu.edu.cn/showproblem.php?pid=1779 线段树 求区间最大值 结点更新
- fzu 1402 中国剩余定理 http://acm.fzu.edu.cn/problem.php?pid=1402
- Problem 1207 半数集问题 from http://acm.fzu.edu.cn/problem.php?pid=1207
- http://acm.hdu.edu.cn/showproblem.php?pid=2845&&最大不连续数和
- Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
- http://acm.fzu.edu.cn/problem.php?pid=2113 数位DP
- Problem 1582 众数问题 from http://acm.fzu.edu.cn/problem.php?pid=1582
- Problem 1607 Greedy division from http://acm.fzu.edu.cn/problem.php?pid=1607
- Problem 1202 信与信封问题 from http://acm.fzu.edu.cn/problem.php?pid=1202
- Problem 1453 Bignum Arithmetic from http://acm.fzu.edu.cn/problem.php?pid=1453
- Problem 1046 Tempter of the Bone, from http://acm.fzu.edu.cn/problem.php?pid=1046
- http://acm.hdu.edu.cn/showproblem.php?pid=1698
- 最大连续子序列http://acm.hdu.edu.cn/showproblem.php?pid=1231
- http://acm.fzu.edu.cn/problem.php?pid=1564 C(n,k)和素数P的问题
- 最大报销额 http://acm.hdu.edu.cn/showproblem.php?pid=1864
- Problem 1410 变位词 from http://acm.fzu.edu.cn/problem.php?pid=1410
- http://acm.hdu.edu.cn/showproblem.php?pid=1863
- http://acm.hdu.edu.cn/showproblem.php?pid=1709