国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

Permutation Sequence

2019-11-14 12:04:35
字體:
供稿:網(wǎng)友

The set [1,2,3,…,n] contains a total of n! unique permutations.

By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):

"123""132""213""231""312""321"

 

Given n and k, return the kth permutation sequence.

Note: Given n will be between 1 and 9 inclusive.

void visit(int n, int k, int pos, int &count, bool flag[], int result[]){	if (count == k)	{		return;	}	if (pos == n)	{		count++;		if (count == k)		{			for (int i = 0; i < n; i++)			{				cout << result[i];			}			cout << endl;		}		return;	}	for (int i = 0; i < n; i++)	{		if (flag[i])		{			result[pos] = i+1;			flag[i] = false;			visit(n, k, pos+1, count, flag, result);			flag[i] = true;		}	}}void fun(int n, int k){	bool flag[n];	memset(flag, true, sizeof(flag));	int result[n];	int count = 0;	visit(n, k, 0, count, flag, result);}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 綦江县| 延津县| 阳原县| 新巴尔虎左旗| 化州市| 泸水县| 墨江| 礼泉县| 班玛县| 老河口市| 唐河县| 望奎县| 张掖市| 中江县| 涿鹿县| 凌云县| 玛曲县| 大连市| 罗源县| 四会市| 忻城县| 留坝县| 五原县| 大田县| 云霄县| 休宁县| 鹤庆县| 勐海县| 湖北省| 上杭县| 栾城县| 夏邑县| 广平县| 炉霍县| 腾冲县| 寻乌县| 徐州市| 泰兴市| 巴南区| 香河县| 泾川县|