总时间限制: 
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. 上下切换js

    <div class="wview"> <span class="prevs" id="prevs-j"></ ...

  2. HDU 1166 敌兵布阵(线段树 单点更新)

     点我看题目  题意 :HDU的中文题也不常见....这道题我就不详述了..... 思路 :这个题用线段树用树状数组都可以,用线段树的时候要注意输入那个地方,输入一个字符串的时候不要紧接着输入两个数字 ...

  3. 使用Eclipse调试Android Native Application---cocos2d-x + Eclipse + Android + ndk

    纠结很多天的ndk 调试, 终于在 mac  下面顺利完成(注意在windows还是没弄成功,蛋疼...) 调试方法: 1:先google, ndk demo .  把ndk 最基本的hellword ...

  4. Java多态的体现之继承

    /** * * 功能:演示多态 */ package com.litao; public class Demo5 { public static void main(String[] args) { ...

  5. MSSQL版本

    (1)661是sql2008 R2的版本号     Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86)   Apr  2 201 ...

  6. 正确使用c语言中的头文件

    我们在使用c编程的时候经常会遇到头文件,前段时间我自己做了个小项目的时候,也遇到了关于头文件的问题. 预处理器发现#include 指令后,就会寻找后跟的文件名并把这个文件包含的内容包含到当前文件中. ...

  7. 【HDOJ】5046 Airport

    DLX简单题目. /* 5046 */ #include <iostream> #include <string> #include <map> #include ...

  8. 【HDOJ】1086 You can Solve a Geometry Problem too

    数学题,证明AB和CD.只需证明C.D在AB直线两侧,并且A.B在CD直线两侧.公式为:(ABxAC)*(ABxAD)<= 0 and(CDxCA)*(CDxCB)<= 0 #includ ...

  9. 【HDOJ】1009 FatMouse' Trade

    这道题目是一道非常简单的贪心,但是我却修改了1h+.原因就是qsort的comp有bug.其实还是题目中的数据可以为0.除数为0真的要慎重啊.后来改为结构体,加一层循环选取最大值,果然ac啊.wa了几 ...

  10. Wpf配置文件属性

    public MainWindow() { InitializeComponent(); this.WindowState = Properties.Settings.Default.WindowSt ...