Gym - 101550C Card Hand Sorting——思维

开始读错题意了,题目要求的是相同花色之间有序,知道这一点以后就枚举一下序列跑几个LCS就好了

#include 
using namespace std;
const int maxn = 100;
char str[maxn];
int n, cnt[4], a[4][maxn];
struct Node {
    int val, type;
}pre[maxn], cur[maxn];
void input(int x, int idx) {
    if (str[1] == 's') a[0][cnt[0]++] = x, pre[idx].type = 0;
    else if (str[1] == 'h') a[1][cnt[1]++] = x, pre[idx].type = 1;
    else if (str[1] == 'd') a[2][cnt[2]++] = x, pre[idx].type = 2;
    else a[3][cnt[3]++] = x, pre[idx].type = 3;
}
bool cmp1(int x, int y) { return x < y; }
bool cmp2(int x, int y) { return x > y; }
int dp[maxn][maxn];
int main() {
    scanf("%d", &n);
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++) {
        scanf("%s", str);
        if (isdigit(str[0])) input(str[0]-'0', i), pre[i].val = str[0]-'0';
        else if (str[0] == 'T') input(10, i), pre[i].val = 10;
        else if (str[0] == 'J') input(11, i), pre[i].val = 11;
        else if (str[0] == 'Q') input(12, i), pre[i].val = 12;
        else if (str[0] == 'K') input(13, i), pre[i].val = 13;
        else input(14, i), pre[i].val = 14;
    }
    int ans = n;
    int b[4] = {0, 1, 2, 3};
    do {
        for (int s = 0; s < 16; s++) {
            int num = 0;
            for (int i = 0; i < 4; i++) {
                if (s & (1<

 

你可能感兴趣的:(思维,动态规划)