太难了 没有AC的 有大佬要论一下思路么 第一题是dp么
第一题:扑克牌
int main() { while (scanf("%d %d", &n, &m) != EOF) { cl(dp, 0); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) { for (int num = 0; num <= min(4, j); num++) { dp[i][j] = (dp[i][j] + dp[i - 1][j - num]) % mod; } } } printf("%lld\n", dp[n][m]); } return 0; }
第二题
int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); for (int i = 1; i <= n; i++) ma[b[i]] = i; for (int i = 1; i <= n; i++) a[i] = ma[a[i]]; l[n] = n; for (int i = n - 1; i >= 1; i--) { if (a[i] > a[i + 1]) l[i] = i; else l[i] = l[i + 1]; } int Min = 0x3f3f3f3f; for (int i = 1; i <= n; i++) { int prelen = i - 1; int suflen = n - (l[i] + 1) + 1; Min = min(Min, prelen + suflen); } printf("%d\n", Min); return 0; }
全部评论
(3) 回帖