简单题,  先是我的代码,再附上#include<algorithm> 里的另一个函数的妙用,:next_permutation();


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>

using namespace std;

int dp[101][101][2];

int main()
{
	freopen("in.txt","r",stdin);
	int i,j,k;
	int t;
	
	dp[1][0][0]=1;
	dp[1][0][1]=1;
	dp[1][1][0]=0;
	dp[1][1][0]=0;
	for (i=2;i<101;i++)
	{
		dp[i][0][0]=dp[i-1][0][0]+dp[i-1][0][1];
		dp[i][0][1]=dp[i-1][0][0];
	}
	for (i=2;i<101;i++)
	{
		for (j=0;j<i;j++)
		{
			dp[i][j][0]=dp[i-1][j][0]+dp[i-1][j][1];
			dp[i][j][1]=dp[i-1][j][0]+dp[i-1][j-1][1];
		}
	}
	
	scanf("%d",&t);
	while (t--)
	{
		int num;
		scanf("%d%d%d",&num,&i,&j);

		printf("%d %d\n",num,dp[i][j][0]+dp[i][j][1]);
	}


	return 0 ;
}






#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int ncase;

int main()
{
    scanf("%d", &ncase);
    for ( int icase = 0 ; icase < ncase ; icase++ )
    {
        int tcase;
        char str[100];
        scanf("%d%s", &tcase, str);
        if ( next_permutation(str, str+strlen(str)) )
            printf("%d %s\n", tcase, str);
        else printf("%d BIGGEST\n", tcase);
    }
    return 0;
}




The Next Permutation


Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 497

 

Accepted: 357


Description


For this problem, you will write a program that takes a (possibly long) string of decimal digits, and outputs the permutation of those decimal digits that has the next larger value (as a decimal number) than the input number. For example:

123 -> 132
279134399742 -> 279134423799

It is possible that no permutation of the input digits has a larger value. For example, 987.


Input


The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set is a single line that contains the data set number, followed by a space, followed by up to 80 decimal digits which is the input value.


Output


For each data set there is one line of output. If there is no larger permutation of the input digits, the output should be the data set number followed by a single space, followed by the string BIGGEST. If there is a solution, the output should be the data set number, a single space and the next larger permutation of the input digits.


Sample Input


3 1 123 2 279134399742 3 987


Sample Output


1 132 2 279134423799 3 BIGGEST


Source


Greater New York Regional 2009