Guest User

Untitled

a guest
Jan 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. int main()
  2. {
  3. int n;
  4. cin>>n;
  5. int A[n];
  6. f(i,0,n) cin>>A[i];
  7. int k;
  8. cin>>k;
  9. int dp[n][k+1];// dp[i][j] = number of sequences of size j ending at position i
  10. dp[0][1]=1;
  11. f(i,1,n)
  12. {
  13. dp[i][1]=1;
  14. f(j,2,k+1)
  15. {
  16. dp[i][j]=0;
  17. f(p,0,i)
  18. {
  19. if(A[p]<A[i])
  20. {
  21. dp[i][j]+=dp[p][j-1];
  22. }
  23. }
  24. }
  25. }
  26. int ans=0;
  27. f(i,0,n) ans+=dp[i][k];
  28. cout<<ans<<"\n";
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment