POJ1405Heritage大树相乘
来源:互联网 发布:java设计工程师学习 编辑:程序博客网 时间:2024/05/01 07:19
H - Heritage
Crawling in process...Crawling failedTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit
Description
Your rich uncle died recently, and the heritage needs to be divided among your relatives and the church (your uncle insisted in his will that the church must get something). There are N relatives (N <= 18) that were mentioned in the will. They are sorted in descending order according to their importance (the first one is the most important). Since you are the computer scientist in the family, your relatives asked you to help them. They need help, because there are some blanks in the will left to be filled. Here is how the will looks:
Relative #1 will get 1 / ... of the whole heritage,
Relative #2 will get 1 / ... of the whole heritage,
---------------------- ...
Relative #n will get 1 / ... of the whole heritage.
The logical desire of the relatives is to fill the blanks in such way that the uncle's will is preserved (i.e the fractions are non-ascending and the church gets something) and the amount of heritage left for the church is minimized.
Relative #1 will get 1 / ... of the whole heritage,
Relative #2 will get 1 / ... of the whole heritage,
---------------------- ...
Relative #n will get 1 / ... of the whole heritage.
The logical desire of the relatives is to fill the blanks in such way that the uncle's will is preserved (i.e the fractions are non-ascending and the church gets something) and the amount of heritage left for the church is minimized.
Input
The only line of input contains the single integer N (1 <= N <= 18).
Output
Output the numbers that the blanks need to be filled (on separate lines), so that the heritage left for the church is minimized.
Sample Input
2
Sample Output
23
<pre name="code" class="cpp">#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){ //数组a储存an-1,数组sum存在an int i,j,k,p,m,N,a[50000]= {0},sum[50000]= {0}; scanf("%d",&N); a[0]=2; printf("2\n"); for(i=1,m=1; i<N; i++) { for(j=0; j<m; j++) { for(k=0; k<m; k++) { if(k==0)//k=0时即是个位数,要减1,代表(an-1 - 1) sum[j+k]+=a[j]*(a[k]-1); else sum[j+k]+=a[j]*a[k]; } } m=j+k;//求和之后的和的最大位数 sum[0]+=1; for(j=0; j<m; j++)//进位 { if(sum[j]>9) { sum[j+1]+=sum[j]/10; sum[j]%=10; } a[j]=sum[j];//把结果赋给a[j],继续上述循环过程 } for(k=m; sum[k]==0; k--); m=k+1;//缺失了不AC for(j=k; j>=0; j--) { printf("%d",sum[j]); sum[j]=0;//清除每次sum[j]带来的影响 } printf("\n"); } return 0;}
这个数列的前几项如下:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
通项:a[i]=2(i=0)
a[i]=a[i-1]*(a[i-1]-1)+1;
0 0
- POJ1405Heritage大树相乘
- 大树相乘的实现
- POJ1405Heritage
- 大树
- 大树小草论
- 做一棵大树
- 大树与松鼠
- 当一棵大树
- 游戏 - 大树与松鼠
- 活着就要成为大树
- 长成大树,长成灌木
- 大树加法、乘法
- 大树和芦苇
- 美丽的大树
- hdu1002 大树相加
- 大树阶乘模板
- hdu 1250 大树
- hdu 1715 大树相加
- 十进制,二进制,八进制
- 利用runtime动态生成对象?
- 通过路由器映射 配置 远程访问
- git及svn操作备忘
- vector的插入操作
- POJ1405Heritage大树相乘
- 你还在苦逼地findViewById吗?使用ButterKnife从此轻松定义控件
- Activity随手势滑动退出,及模糊Dialog(类似于IOS的效果)
- Android线程和线程Handler基础一览
- 离开单位后社保会被冻结吗?
- HTML中的<head>标签及其内容
- fatal error C1047 对象或库文件“….Win32Release xxx.obj”是使用比创建其他对象所用编译器旧的编译器创建的;请重新生成旧的对象和库
- hdu 1102 Constructing Roads
- http中get方法和post方法的区别