当前位置: 首页 > 工具软件 > t-shirts > 使用案例 >

UVA12022 Ordering T-shirts【数学+打表】

鲁鹏
2023-12-01

Working in a boutique folding and putting in order T-shirts according to their sizes seems very easy. But is it really so simple?
    Given n objects of different sizes, how many different arrangements can be done using relationships ‘¡’ and ‘=’?
    For instance, with 2 objects, A and B, we have 3 possible arrangements:
A=B A¡B B¡A
    With 3 objects, A, B and C, you must conclude that 13 different arrangements exist:
A=B=C A=B¡C A¡B=C A¡B¡C A¡C¡B A=C¡B B¡A=C B¡A¡C B¡C¡A B=C¡A C¡A=B C¡A¡B C¡B¡A
Input
The first line of the input contains an integer, t, indicating the number of test cases. For each test case, one line appears, that contains a number n, 1 ≤ n ≤ 11, representing the number of objects.
Output
For each test case, the output should contain a single line with the number representing the different arrangements you can do with n objects.
Sample Input
4
1
2
3
4
Sample Output
1
3
13
75

问题链接UVA12022 Ordering T-shirts
问题简述:(略)
问题分析:数学问题,离线打表是必要的。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA12022 Ordering T-shirts */

#include <bits/stdc++.h>

using namespace std;

const int num[] = {1, 1, 3, 13, 75, 541, 4683, 47293, 545835, 7087261, 102247563, 1622632573};

int main()
{
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        printf("%d\n", num[n]);
    }

    return 0;
}

AC的C++语言程序如下:

/* UVA12022 Ordering T-shirts */

#include <bits/stdc++.h>

using namespace std;

const int N = 11;
int nr[N + 1][N + 1], num[N + 1];

int main()
{
    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= i; j++)
            if (i == j) nr[i][j] = 1;
            else if (j == 0) nr [i][j] = 1;
            else if (j == 1) nr [i][j] = i;
            else nr[i][j] = nr[i - 1][j] + nr[i - 1][j - 1];

    num[0] = 1;
    num[1] = 1;
    num[2] = 3;
    for (int i = 3; i <= N; i++)
        for (int j = 0; j <= i; j++)
            num[i] += nr[i][j] * num[i - j];

    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        printf("%d\n", num[n]);
    }

    return 0;
}
 类似资料: