总时间限制: 
5000ms

内存限制: 
65536kB
描述
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.

输入
The only line of input contains the single integer N (1 <= N <= 18).
输出
Output the numbers that the blanks need to be filled (on separate lines), so that the heritage left for the church is minimized.
样例输入
2
样例输出
2
3
来源
ural 1108
贪心的来想如果只有一个人那就是1/2 , 两个个人就是1/2,1/3 ,还剩下1/6,如果还要分给下一个人,就会1/7 ,还剩1/42,同理下一个人得1/43,然后看出规律了吧,
然后我们就涉及到了高精乘,然而普通高精乘是过不了的,所以可以用fft,或者ntt这种黑科技(奇技淫巧)。
以下是我ntt
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std ;
typedef long long LL ;
const int P = ( << ) + , N = << , G = , NUM = ;
int m , len , l1 , l2 ;
LL a[N] , b[N] , wn[NUM] ; void Init( )
{
scanf( "%d" , &m ) ;
if( m > ) l1 = , l2 = , a[] = , b[] = , len = ;
} LL quick_mod( LL a , LL b , LL m )
{
LL ans = 1ll ;
a %= m ;
while( b )
{
if( b & ) ans = ans * a % m ;
b >>= ;
a = a * a % m ;
}
return ans ;
} void Rader( LL a[] , int n )
{
int j = n >> ;
for( int i = ; i < n - ; ++i )
{
if( i < j ) swap( a[i] , a[j] ) ;
int k = n >> ;
while( j >=k )
{
j -= k ;
k >>= ;
}
if( j < k ) j += k ;
} } void NTT( LL a[] , int n , int on )
{
Rader( a , n ) ;
int id = ;
for( int h = ; h <= n ; h <<= )
{
++id ;
for( int j = ; j < n ; j += h )
{
LL w = ;
for( int k = j ; k < j + ( h >> ) ; ++k )
{
LL u = a[k] % P ;
LL t = w * a[k+(h>>)] % P ;
a[k] = ( u + t ) % P ;
a[k+(h>>)] = ( u - t + P ) % P ;
w = w * wn[id] % P ;
}
}
}
if( on == - )
{
for( int i = ; i < ( n >> ) ; ++i ) swap( a[i] , a[n-i] ) ;
LL inv = quick_mod( n , P - , P ) ;
for( int i = ; i < n ; ++i ) a[i] = a[i] * inv % P ;
} } void Conv( LL a[] , LL b[] , int n )
{
NTT( a , n , ) ;
NTT( b , n , ) ;
for( int i = ; i < n ; ++i )
a[i] = a[i] * b[i] % P ;
NTT( a , n , - ) ;
} void Transfer( LL a[] , int n )
{
for( int i = ; i < n ; ++i )
{
a[i+] += a[i]/ ;
a[i] %= ;
if( a[i] ) l1 = i ;
} ++l1 ;
} void Update( LL b[] , int n )
{
int t = ; l2 = n ;
for( int i = ; i <= n ; ++i )
{
b[i] = a[i] + t ;
t = b[i]/ ; b[i] %= ;
}
if( b[l1] ) ++l2 ; } void print( LL b[] , int n )
{
for( int i = l2 - ; i >= ; --i ) putchar( b[i] + '' ) ;
puts( "" ) ;
} void Length( int l1 , int l2 )
{
while( len <= (l1<<) || len <= (l2<<) ) len <<= ;
} void Getwn( )
{
for( int i = ; i < NUM ; ++i ) wn[i] = quick_mod( G , (P-)/(<<i) , P ) ;
} void Solve( )
{
if( m >= ) puts( "" ) ;
if( m >= ) puts( "" ) ;
if( m <= ) return ;
Getwn( ) ;
for( int i = ; i <= m ; ++i )
{
for( int i = l2 ; i <= len ; ++i ) b[i] = ;
Conv( a , b , len ) ;
Transfer( a , len ) ;
Update( b , l1 ) ;
print( b , l2 ) ;
Length( l1 , l2 ) ;
} } int main( )
{
Init( ) ;
Solve( ) ;
return ;
}

NOIopenjudge 407:Heritage的更多相关文章

  1. R自动数据收集第一章概述——《List of World Heritage in Danger》

      导包     library(stringr) library(XML) library(maps) heritage_parsed <- htmlParse("http://en ...

  2. Atitit jsr规范有多少个  407个。Jsr规范大全

    Atitit jsr规范有多少个  407个.Jsr规范大全 1.1. JCP维护职能是发展和更新.1 1.2. Java技术规范.参考实现(RI).技术兼容包(TCK)1 1.3. JCP维护的规范 ...

  3. 洛谷P1827 美国血统 American Heritage

    P1827 美国血统 American Heritage 54通过 90提交 题目提供者JOHNKRAM 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 农夫约翰非 ...

  4. USACO3.42American Heritage(二叉树)

    已知中前 求后序 递归一下 有一些小细节 /* ID: shangca2 LANG: C++ TASK: heritage */ #include <iostream> #include& ...

  5. USACO 3.4 American Heritage

    American Heritage Farmer John takes the heritage of his cows very seriously. He is not, however, a t ...

  6. HTTP请求错误400、401、402、403、404、405、406、407、412、414、500、501、502解析

    HTTP 错误 400 400 请求出错 由于语法格式有误,服务器无法理解此请求.不作修改,客户程序就无法重复此请求. HTTP 错误 401 401.1 未授权:登录失败 此错误表明传输给服务器的证 ...

  7. Spring Cloud项目中通过Feign进行内部服务调用发生401\407错误无返回信息的问题

    问题描述 最近在使用Spring Cloud改造现有服务的工作中,在内部服务的调用方式上选择了Feign组件,由于服务与服务之间有权限控制,发现通过Feign来进行调用时如果发生了401.407错误时 ...

  8. LintCode 407: Plus One

    LintCode 407: Plus One 题目描述 给定一个非负数,表示一个数字数组,在该数的基础上+1,返回一个新的数组. 该数字按照位权大小进行排列,位权最大的数在列表的最前面. 样例 给定 ...

  9. (第六场)Heritage of skywalkert 【玄学】

    题目链接:https://www.nowcoder.com/acm/contest/144/J 标题:J.Heritage of skywalkert | 时间限制:1 秒 | 内存限制:256M s ...

随机推荐

  1. c++ 联合体

    联合体分配的内存大小是成员变量中最大变量的大小 联合体的成员变量共享内存 小段模式(X86就是) 低位数据存在低地址单元 大端模式                     高位字节存在低地址单元

  2. gei shilei d

    body, p { margin: 0; padding: 0; font-size: 16px; } div { margin: 0 auto; } .wrapper { width: 1080px ...

  3. HDU 1176 免费馅饼(DP)

    点我看题目 题意 : 中文题.在直线上接馅饼,能接的最多是多少. 思路 :这个题其实以前做过.....你将这个接馅饼看成一个矩阵,也不能说是一个矩阵,反正就是一个行列俱全的形状,然后秒当行,坐标当列, ...

  4. asp.net将数据库中的数据赋给DropDownList

    当你选定一项进行其他操作时会重新绑定dropdownlist,这样会重新回到第一项,在page_load里加上判断if(!IsPostBack){'这里是你需要绑定dropdownlist的代码'}. ...

  5. VirtualBox虚拟vdi磁盘扩容

    http://blog.chinaunix.net/uid-25627207-id-3342576.html

  6. Hibernate的优缺点

    Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库. Hibernate可以应用在任何使用JDB ...

  7. USCAO3.26Sweet Butter(SPFA)

    最短路复杂度估计错误 以为SPFA是N*m的 用了dij超时 用SPFA直接跑就好了 O(k*e) K 一般为2,3: /* ID: shangca2 LANG: C++ TASK: butter * ...

  8. WordPress OptimizePress插件任意文件上传漏洞

    漏洞版本: WordPress OptimizePress Plugin 1.x 漏洞描述: WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设 ...

  9. Linux kernel 拒绝服务漏洞

    漏洞名称: Linux kernel 拒绝服务漏洞 CNNVD编号: CNNVD-201311-020 发布时间: 2013-11-05 更新时间: 2013-11-05 危害等级:    漏洞类型: ...

  10. Win32下 Qt与Lua交互使用(二):在Lua脚本中使用Qt类

    话接上篇.成功配置好Qt+Lua+toLua后,我们可以实现在Lua脚本中使用各个Qt的类.直接看代码吧. #include "include/lua.hpp" #include ...