Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- int main()
- {
- ifstream in("zebughil.in");
- ofstream out("zebughil.out");
- int t = 1;
- while(t--)
- {
- int n, g;
- in >> n >> g;
- vector<long long> v(n);
- for(int i = 0; i < n; ++i)
- in >> v[i];
- vector<long long> dp(1 << n);
- for(int state = 0; state < (1 << n); ++state)
- {
- long long sum = 0;
- for(int i = 0; i < n; ++i)
- if((state & (1 << i)) != 0)
- sum += v[i];
- if(sum <= g)
- dp[state] = 1;
- else
- {
- dp[state] = (1 << 62);
- for(int sub = (state - 1) & state; sub > 0; sub = (sub - 1) & state)
- {
- dp[state] = min(dp[state], dp[sub] + dp[state - sub]);
- if(state == (1 << n) - 1)
- cout << sub << " " << state-sub << "\n";
- }
- }
- }
- out << dp[(1 << n) - 1] << "\n";
- }
- in.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement