亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pku1037.txt

?? 兩種解決方案 Richard just finished building his new house. Now the only thing the house misses is a cute l
?? TXT
字號:
acm 1037: from pku
題型:動態歸劃
原題:
A decorative fence 
Time Limit:1000MS  Memory Limit:10000K
Total Submit:1323 Accepted:368 

Description
Richard just finished building his new house. Now the only thing the house misses is a cute little wooden fence. He had no idea how to make a wooden fence, so he decided to order one. Somehow he got his hands on the ACME Fence Catalogue 2002, the ultimate resource on cute little wooden fences. After reading its preface he already knew, what makes a little wooden fence cute. 
A wooden fence consists of N wooden planks, placed vertically in a row next to each other. A fence looks cute if and only if the following conditions are met: 
?The planks have different lengths, namely 1, 2, . . . , N plank length units. 
?Each plank with two neighbors is either larger than each of its neighbors or smaller than each of them. (Note that this makes the top of the fence alternately rise and fall.) 
It follows, that we may uniquely describe each cute fence with N planks as a permutation a1, . . . , aN of the numbers 1, . . . ,N such that (any i; 1 < i < N) (ai ? ai?1)*(ai ? ai+1) > 0 and vice versa, each such permutation describes a cute fence. 
It is obvious, that there are many di erent cute wooden fences made of N planks. To bring some order into their catalogue, the sales manager of ACME decided to order them in the following way: Fence A (represented by the permutation a1, . . . , aN) is in the catalogue before fence B (represented by b1, . . . , bN) if and only if there exists such i, that (any j < i) aj = bj and (ai < bi). (Also to decide, which of the two fences is earlier in the catalogue, take their corresponding permutations, find the first place on which they differ and compare the values on this place.) All the cute fences with N planks are numbered (starting from 1) in the order they appear in the catalogue. This number is called their catalogue number. 




After carefully examining all the cute little wooden fences, Richard decided to order some of them. For each of them he noted the number of its planks and its catalogue number. Later, as he met his friends, he wanted to show them the fences he ordered, but he lost the catalogue somewhere. The only thing he has got are his notes. Please help him find out, how will his fences look like.

Input
The first line of the input file contains the number K (1 <= K <= 100) of input data sets. K lines follow, each of them describes one input data set. 
Each of the following K lines contains two integers N and C (1 <= N <= 20), separated by a space. N is the number of planks in the fence, C is the catalogue number of the fence. 
You may assume, that the total number of cute little wooden fences with 20 planks fits into a 64-bit signed integer variable (long long in C/C++, int64 in FreePascal). You may also assume that the input is correct, in particular that C is at least 1 and it doesn抰 exceed the number of cute fences with N planks.

Output
For each input data set output one line, describing the C-th fence with N planks in the catalogue. More precisely, if the fence is described by the permutation a1, . . . , aN, then the corresponding line of the output file should contain the numbers ai (in the correct order), separated by single spaces.

Sample Input


2
2 1
3 3

Sample Output


1 2
2 3 1
解答:
/--------------------------------Solution1--------------------------------------------------------/
/*
down(n,1)=0;
down(n,j+1)=down(n,j)+up(n-1,j);
up(n,i)=down(n,n+1-i);

*/

//#include<iostream>
//using namespace std;
#include<stdio.h>
#include "memory.h"
 const int N=20;
 __int64 down[N+1][N+1];
 __int64 up[N+1][N+1];
void initial()
{
  memset(down,0,sizeof(down));
  memset(up,0,sizeof(up));

       int i,j;
	//for(i=1;i<=N;i++)
	//	down[i][1]=0;
	up[1][1]=1;
	for(i=2;i<=N;i++)
		for(j=2;j<=i;j++)
		{
			down[i][j]=down[i][j-1]+up[i-1][j-1];
			up[i][i+1-j]=down[i][j];
		}
				
}
void goUp(int *arr,int n,__int64 C,int limit);
void goDown(int *arr,int n,__int64 C,int limit)
{
	if(n==1)
	{
		//cout<<arr[n]<<endl;return;
		printf("%d\n",arr[n]);return;
	}
	int i,j;
	for(i=limit;i<=n;i++)
	{
     C-=down[n][i];
	 if(C<1)
	 {
		 //cout<<arr[i]<<' ';
		 printf("%d ",arr[i]);
		 for(j=i;j<n;j++)
			 arr[j]=arr[j+1];
		 goUp(arr,n-1,C+down[n][i],i);//goUp函數中point i 取不到 
		 break;
	 }

	}



}
void goUp(int *arr,int n,__int64 C,int limit)
{
	if(n==1)
	{
		//cout<<arr[n]<<endl;return;
		printf("%d\n",arr[n]);return;
	}
	int i,j;
	for(i=1;i<limit;i++)
	{
		C-=up[n][i];
		if(C<1)
		{
			//cout<<arr[i]<<' ';
			printf("%d ",arr[i]);
			for(j=i;j<n;j++)
				arr[j]=arr[j+1];
			goDown(arr,n-1,C+up[n][i],i);
			break;
		}

	}
	
}
void PermFence(int *arr,int n,__int64 C)
{
	
	if(n==1)
	{ //cout<<arr[n]<<endl;return;
		printf("%d\n",arr[n]);return;
	}
    int i,j;
	for( i=2;i<=n;i++)
	{
		C-=up[n][i-1];
		if(C<1)
		{
			//cout<<arr[i-1]<<' ';
			printf("%d ",arr[i-1]);
			for(j=i-1;j<n;j++)
				arr[j]=arr[j+1];
			 goDown(arr,n-1,C+up[n][i-1],i-1);
			break;
		}
		C-=down[n][i];
		if(C<1)
		{
			//cout<<arr[i]<<' ';
			 printf("%d ",arr[i]);
			for(j=i;j<n;j++)
				arr[j]=arr[j+1];
		    goUp(arr,n-1,C+down[n][i],i);
			break;
		}

	}

}
int main()
{
	initial();
	int i,j,n;
	int cn;
	__int64 C;
	//cout<<"please input the test times"<<endl;
	//cin>>n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		
		//cout<<"please input the N and C"<<endl;
		//cin>>cn>>C;
		scanf("%d%I64d",&cn,&C);
		int *arr=new int[cn+1];
		for(j=1;j<=cn;j++)
			arr[j]=j;
		//printf("the N and C is:%d ,%Ld\n",cn,C);
		PermFence(arr,cn,C);
		delete[] arr;
	}


	return 0;
}
/--------------------------------------------------------------------------------------------------/


/---------------------------Solution2-------------------------------------------------------------/
//這種算法用的是回溯搜索-----超時了,不過思路比較簡單!

#include<iostream>
using namespace std;
#include "stdio.h"
template<class T>
void Swap(T &a,T &b)
{

	T tmp=a;
	a=b;
	b=tmp;

}
template<class T>
void Sort(T list[],int k,int i,bool bFirst)
{
	int j;
  if(bFirst)
  {
	T tmp=list[i];
	for( j=i;j>k+1;j--)
	 list[j]=list[j-1];
	list[j]=tmp;
  }
  else
  {
	T tmp=list[k+1];
	for( j=k+1;j<i;j++)
		list[j]=list[j+1];
	 list[j]=tmp;
  }
}
template<class T>
void PermFence(T list[],int k,int n, __int64 C, __int64 &pCnt)
{
 if(pCnt==C)return;

   int i,j;
	if(k>n-1)
	{
		/*
		for(i=1;i<n-1;i++)
			if((list[i]-list[i-1])*(list[i]-list[i+1])>0)
				continue;
			else return;
	*/
		pCnt++;	
		if(pCnt==C)
		{
			for(i=0;i<n;i++)
				cout<<list[i]<<' ';
			cout<<endl;		

		}

	}
	else
	{
       
		for(i=k;i<n;i++)
		{
			
			Swap(list[i],list[k]);			
			if(k>1)
			{
				
				 if((list[k-1]-list[k-2])*(list[k-1]-list[k])<0)
				 {
					 Swap(list[i],list[k]);
					 continue;

				 }
				

			}
			Sort(list,k,i,true);
			PermFence(list,k+1,n,C,pCnt);
			Sort(list,k,i,false);
			Swap(list[i],list[k]);
		}
	}
	



}


int main()
{
	int i,j,n;
	int N;
	 __int64 C;
	//cout<<"please input the test times"<<endl;
	cin>>n;
	for(i=0;i<n;i++)
	{
        __int64 pCnt=0;
		//cout<<"please input the N and C"<<endl;
		//cin>>N>>C;
		scanf("%d%I64d",&N,&C);
		int *arr=new int[N];
		for(j=0;j<N;j++)
			arr[j]=j+1;
		PermFence(arr,0,N,C,pCnt);
		delete[] arr;


	}


	return 0;
}
/--------------------------------------------------------------------------------------------------------/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国产乱码久久久久久影片| 一本到不卡精品视频在线观看 | 亚洲一区二区三区爽爽爽爽爽| caoporm超碰国产精品| 国产精品丝袜黑色高跟| www.欧美日韩| 亚洲一区二区三区四区五区中文| 欧美日韩在线播放一区| 蜜臀精品久久久久久蜜臀| 久久嫩草精品久久久精品| 国产91综合一区在线观看| 国产校园另类小说区| 99精品视频在线观看免费| 亚洲精品国产一区二区三区四区在线| 色八戒一区二区三区| 天使萌一区二区三区免费观看| 日韩一级高清毛片| 国产一区二区91| 国产精品国产自产拍在线| 在线观看日韩一区| 美女www一区二区| 国产精品日产欧美久久久久| 在线精品亚洲一区二区不卡| 婷婷久久综合九色综合伊人色| 欧美一二三区在线观看| 成人高清在线视频| 首页国产欧美久久| 国产亚洲一区二区三区在线观看| 色综合久久久久综合体桃花网| 午夜亚洲福利老司机| 26uuu亚洲综合色| 色婷婷一区二区三区四区| 秋霞电影网一区二区| 最近中文字幕一区二区三区| 日韩一级黄色片| 成人h动漫精品一区二| 丝袜国产日韩另类美女| 国产精品家庭影院| 久久日一线二线三线suv| 色婷婷av一区二区| 国产成人综合亚洲网站| 日韩综合在线视频| 亚洲精品一二三| 久久久久久久性| 欧美一卡在线观看| 色欧美日韩亚洲| 国产精品69久久久久水密桃| 亚洲国产一区二区三区青草影视| 国产日韩成人精品| 91精品国产综合久久香蕉麻豆| 波多野结衣一区二区三区| 日本欧美肥老太交大片| 亚洲猫色日本管| 欧美激情一区不卡| 久久久久久电影| 欧美成人aa大片| 欧美日本视频在线| 欧洲视频一区二区| 99久久亚洲一区二区三区青草| 国产一区二区三区免费在线观看| 日一区二区三区| 午夜不卡av免费| 五月综合激情婷婷六月色窝| 亚洲一区二区三区三| 玉米视频成人免费看| 亚洲欧美日韩国产综合在线| 中文字幕日韩精品一区| 国产精品无人区| 国产午夜亚洲精品不卡| 久久五月婷婷丁香社区| 精品成人a区在线观看| 日韩欧美国产一区二区三区| 欧美一区中文字幕| 91麻豆精品国产91| 欧美一级片在线观看| 欧美日韩电影一区| 欧美精品123区| 91麻豆精品国产91久久久使用方法 | 制服.丝袜.亚洲.中文.综合| 欧美久久久一区| 欧美视频精品在线| 欧美人与禽zozo性伦| 欧美猛男男办公室激情| 欧美精品第1页| 4438成人网| 精品久久久久香蕉网| 欧美精品一区二区精品网| 亚洲精品一区二区三区蜜桃下载 | 一区二区三区四区中文字幕| 国产精品久久久久天堂| 亚洲色大成网站www久久九九| 亚洲精品成人精品456| 亚洲成人精品一区| 毛片不卡一区二区| 国产电影一区在线| 91激情在线视频| 欧美一区二区在线不卡| 精品盗摄一区二区三区| 中文字幕av在线一区二区三区| 亚洲欧洲综合另类| 日韩1区2区日韩1区2区| 国产成人综合网站| 在线观看成人免费视频| 欧美一区二区视频观看视频| 久久人人爽人人爽| 一区二区三区欧美激情| 久久精品99久久久| 波波电影院一区二区三区| 欧美片网站yy| 国产嫩草影院久久久久| 五月综合激情婷婷六月色窝| 国产精品一区二区不卡| 91成人免费网站| 亚洲精品一线二线三线无人区| 国产精品激情偷乱一区二区∴| 日韩专区欧美专区| 成人午夜电影网站| 国产mv日韩mv欧美| 午夜久久久久久| 欧美色大人视频| 99久久综合精品| 91麻豆精品国产91久久久| 亚洲国产高清在线观看视频| 亚洲国产乱码最新视频| 国产 日韩 欧美大片| 欧美老女人第四色| 成人免费在线播放视频| 免费看欧美美女黄的网站| 91一区二区在线| 久久综合色一综合色88| 亚洲一二三四久久| 不卡视频一二三| 久久综合九色综合97婷婷女人| 亚洲一区二区三区四区在线观看| 国产.欧美.日韩| 日韩欧美成人一区二区| 亚洲成人高清在线| 色综合天天在线| 国产亚洲欧美色| 三级在线观看一区二区| 欧美伊人久久久久久午夜久久久久| 久久人人超碰精品| 捆绑调教美女网站视频一区| 欧美日韩亚洲综合在线| 一区二区三区日本| 成人国产精品免费网站| 久久久久久久精| 精品一二三四区| 欧美一区二区三区喷汁尤物| 亚洲国产精品久久不卡毛片| 色域天天综合网| 成人欧美一区二区三区小说| 粉嫩在线一区二区三区视频| 久久夜色精品国产噜噜av| 免费不卡在线观看| 日韩一区二区免费在线电影| 亚洲国产综合人成综合网站| 91久久精品一区二区二区| 亚洲免费电影在线| 色狠狠综合天天综合综合| 亚洲欧美欧美一区二区三区| 99久久精品国产导航| 国产精品久久久久四虎| 99久久精品免费看国产| 亚洲日本一区二区三区| 91网上在线视频| 亚洲免费观看视频| 在线观看日韩毛片| 午夜精品影院在线观看| 欧美二区乱c少妇| 日韩经典一区二区| 日韩美女一区二区三区| 久久99最新地址| 国产色产综合色产在线视频| 成人性生交大片| 亚洲女与黑人做爰| 在线观看91视频| 日本中文字幕一区二区视频 | 亚洲国产日韩在线一区模特| 在线观看成人免费视频| 日韩激情视频在线观看| 精品国内二区三区| 成人免费福利片| 亚洲乱码日产精品bd| 欧美亚洲国产一区二区三区va | 亚洲va欧美va国产va天堂影院| 欧美日韩视频不卡| 蜜桃视频在线观看一区| 久久精品一区二区三区不卡| 精品一区二区三区免费播放| 日本一区二区视频在线观看| 色综合一个色综合| 日韩精品国产精品| 久久久激情视频| 91小视频在线| 蜜臀av性久久久久蜜臀aⅴ| 日本一区二区三级电影在线观看| 91年精品国产| 美女网站一区二区| 中文字幕一区二区在线播放 |