1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <algorithm> #include <cstdio> #include <cstring> #define ll long long int f[5007][5007]; int a[5007], b[5007]; int n; 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) { for (int j = 1; j <= n; ++j) { f[i][j] = std::max(f[i][j], std::max(f[i - 1][j], f[i][j - 1])); if (a[i] == b[j]) { f[i][j] = std::max(f[i][j], f[i - 1][j - 1] + 1); } } } printf("%d\n", f[n][n]); return 0; } |
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、当输入“4 1 2 3 4 1 3 2 2”时,输出为2。( )
2、当程序运行完毕后,对于所有的1≤i,j≤n,都一定有f[i][j] <= f[n][n]。( )
3、将第18行的f[i][j] = std::max(f[i][j], std::max(f[i – 1][j], f[i][j – 1]));删去后,并不影响程序运行结果。( )
4. 输出的答案满足的性质有( )。
5、如果在16行的循环前加上以下两行:std::sort(a + 1, a + n + 1);std::sort(b + 1, b + n + 1);,则答案会( )。
6、如果输入的a={1,2,…,n}\{1,2,…,n\}{1,2,...,n},而且b数组中数字均为1~n中的正整数,则上述代码等价于下面哪个问题:( )。
