本文主要是介绍【ZOJ】3889 Making Sequence【构造】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
传送门:【ZOJ】3889 Making Sequence
根据题意构造即可。ZOJ月赛我们抢的第二个FBwww
my code:
#include <bits/stdc++.h>
using namespace std ;typedef unsigned long long ULL ;const int MAXN = 205 ;ULL n , a , b , s , t ;
ULL S[MAXN] , T[MAXN] , tmp[MAXN] ;bool calc ( ULL s , ULL a , ULL S[] ) {if ( s > n ) return 0 ;s -= a ;for ( int i = 1 ; i <= s ; ++ i ) S[i] = i ;for ( int i = 0 ; i < a ; ++ i ) {tmp[1] = 1 ;for ( int j = 1 ; j <= s ; ++ j ) {if ( n < tmp[j] || n - tmp[j] < S[j] ) return false ;tmp[j + 1] = tmp[j] + S[j] ;}++ s ;for ( int j = 1 ; j <= s ; ++ j ) S[j] = tmp[j] ;}return true ;
}void solve () {if ( !calc ( s , a , S ) ) printf ( "-1\n" ) ;else for ( int i = 1 ; i <= s ; ++ i ) printf ( "%llu%c" , S[i] , i < s ? ' ' : '\n' ) ;if ( !calc ( t , b , T ) ) printf ( "-1\n" ) ;else for ( int i = 1 ; i <= t ; ++ i ) printf ( "%llu%c" , n - T[i] + 1 , i < t ? ' ' : '\n' ) ;
}int main () {int f = 0 ;while ( ~scanf ( "%llu%llu%llu%llu%llu" , &n , &a , &b , &s , &t ) ) {if ( f ++ ) puts ( "" ) ;solve () ;}return 0 ;
}
这篇关于【ZOJ】3889 Making Sequence【构造】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!