Advertisement
Guest User

Валетный код

a guest
Sep 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define F first
  5. #define S second
  6. #define ll long long
  7.  
  8. using namespace std;
  9.  
  10. int dp[512][123456];
  11.  
  12. int main() {
  13. ios_base::sync_with_stdio(0);
  14. cin.tie(0);
  15. cout.tie(0);
  16. #ifdef LOCAL
  17. freopen("input.txt","r",stdin);
  18. freopen("output.txt","w",stdout);
  19. #endif
  20. int n,m;
  21. cin>>n>>m;
  22. vector <int> a(n);
  23. ll sum = 0;
  24. for ( int i = 0; i < n; i++ ) {
  25. cin>>a[i];
  26. sum += a[i];
  27. }
  28. if ( sum % m == 0 ) {
  29. cout<<n;
  30. return 0;
  31. }
  32. for ( int i = 0; i < n; i++ )
  33. dp[i][a[i]%m] = 1;
  34. for ( int i = 1; i < n; i++ ) {
  35. for ( int j = 0; j < m; j++ ) {
  36. if ( dp[i-1][j] != 0 ) dp[i][j] = max( dp[i][j], dp[i-1][j] + 0 );
  37. if ( dp[i-1][(j-a[i]+m)%m] != 0 ) dp[i][j] = max( dp[i][j], dp[i-1][(j-a[i]+m)%m] + 1 );
  38. }
  39. }
  40. for ( int i = 0; i < n; i++ ) {
  41. for ( int j = 0; j < m; j++ )
  42. cout<<dp[i][j]<<' ';
  43. cout<<endl;
  44. }
  45. cout<<dp[n-1][0];
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement