Advertisement
tuki2501

Possible Path

Feb 3rd, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve(){
  5.     int n, m; cin >> n >> m;
  6.     vector<bitset<4000> > top(m + 1), bot(m + 1);
  7.     for(int i = 1; i <= n; i++){
  8.         copy(bot.begin(), bot.end(), top.begin());
  9.         for(int j = 1; j <= m; j++){
  10.             char t; cin >> t; t -= '0';
  11.             bot[j] = bot[j - 1] | top[j];
  12.             if(bot[j] == 0) bot[j] = 1;
  13.             bot[j] <<= t;
  14.         }
  15.     }
  16.     for(int i = 0; i < 4000; i++)
  17.         if(bot[m][i]) cout << i << ' ';
  18.     cout << '\n';
  19. }
  20.  
  21. int main(){
  22.     ios::sync_with_stdio(0); cin.tie(0);
  23.     int T; cin >> T;
  24.     while(T--) solve();
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement