枚举参考hdu2062-Subset sequence

这段时间一直在查找枚举参考之类的问题,今天正好有机会和大家共享一下.

    推出子集每一个n的位数的法则  num[ n ]  = n * (num[ n - 1 ] + 1 )  ;

    然后进行枚举记录位数,上面的思绪是参考别人的 ,我的相较复杂很多多少,这个优化很多多少。 

    每日一道理
这浓浓的母爱使我深深地认识到:即使你是一只矫健的雄鹰,也永远飞不出母爱的长空;即使你是一条扬帆行驶的快船,也永远驶不出母爱的长河!在人生的路上不管我们已走过多远,还要走多远,我们都要经过母亲精心营造的那座桥!
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>



using namespace std ;



const int maxn = 25 ;

long long  num[ maxn ] ;

int n  ;

long long m ;



int main()

{

	int i ;

	int ans[ maxn ] ;

	int used[ maxn ] ;

	int temp1 , temp2 ;

	num[ 1 ] = 1 ;

	for( int i = 2 ; i <= 25 ; i ++ )

		num[ i ] = i * ( num[ i - 1 ] + 1 ) ;

	while( cin >> n >> m )

	{

		memset( used , 0 , sizeof( used ) ) ;

		int cnt = 0 ;

		while( cnt < n )

		{

			if( m == 0 )

				break ; 

			for( i = 1 ; i <= n ; i++ )

			{

				if( used[ i ] ) 

					continue ;

				if( m > num[ n - cnt - 1 ] + 1 )

					m -= num[ n - cnt - 1 ] + 1 ;

				else

				{

					ans[ ++cnt ] =  i ;

					m-- ;

					used[ i ] = 1 ;

					break ;

				}

			}

		}

		for( i = 1 ; i < cnt ; i++ )

			cout << ans[ i ] << " " ;

		cout << ans[ cnt ] << endl ;

	}

	return 0 ;

}

文章结束给大家分享下程序员的一些笑话语录: 3G普不普及现在已经不是看终端了,而是看应用,有好的,便宜实用的应用,花1000多买个能用的智能手机应该不是什么难事。反过来说,你200元拿一个智能手机,没有好的应用,看个电影要几十元,也是没人用3G。

你可能感兴趣的:(sequence)