fork(2) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. #define N 10
  6.  
  7. int main() {
  8. int P[N] = {7, 51, 8, 10, 3, 6, 12, 3, 9, 8};
  9. int C[N] = {9, 4, 6, 2, 7, 9, 11, 56, 7, 11};
  10.  
  11. int dp[N+1][N+1];
  12. memset(dp, 0, sizeof(dp));
  13.  
  14. for(int x=N-1; x>=0; x--) {
  15. for(int y=N-1; y>=0; y--) {
  16. if(C[x] >= P[y]) {
  17. dp[x][y] = max(1 + dp[x+1][y+1], dp[x+1][y]);
  18. } else {
  19. dp[x][y] = dp[x+1][y];
  20. }
  21. }
  22. }
  23.  
  24. int ret = 0, index=0;
  25. for(int i=0; i<N; i++) {
  26. if(ret < dp[1][i]) {
  27. ret = dp[1][i];
  28. index = i;
  29. }
  30. }
  31. cout << ret << " " << index << endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
5 4