Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define int long long
- #define all(x) x.begin(), x.end()
- #define ar array
- #define IOS \
- std::ios::sync_with_stdio(false); \
- cin.tie(NULL);
- const int inf = 1e12;
- int mx;
- int n;
- vector<pair<int,string>>arr;
- vector<vector<int>>dp;
- int dfs(int idx, int msk){
- if(idx==n){
- if( __builtin_popcount(msk) == mx ) return 0;
- return inf;
- }
- if(dp[idx][msk]!=-1)
- return dp[idx][msk];
- int new_msk= msk;
- string str = arr[idx].second;
- for(int j=0;j<10;j++) {
- int num = (str[j]-'0');
- if(num==1)
- new_msk|=(1<<(10-j));
- }
- dp[idx][msk] = min({arr[idx].first+dfs(idx+1,new_msk),dfs(idx+1,msk)});
- return dp[idx][msk];
- }
- void init()
- {
- set<int>distinct;
- cin>>n;
- arr.resize(n);
- dp=vector<vector<int>>(n+1,vector<int>(( (1<<10)+1),-1));
- for(int i=0;i<n;i++) {
- cin>>arr[i].first>>arr[i].second;
- for(int j=0;j<10;j++){
- if(arr[i].second[j] == '1') distinct.insert(j);
- }
- }
- mx = distinct.size();
- cout<<dfs(0,0)<<endl;
- }
- int32_t main()
- {
- IOS;
- init();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement