fork download
  1. // Author : Ritik Patel
  2. // Institution: Pandit Deendayal Petroleum University
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. #define ub upper_bound // first element > val(itr)
  8. #define lb lower_bound // first element >= val(itr)
  9.  
  10. #define sz(a) int((a).size())
  11. #define all(c) (c).begin(),(c).end()
  12. #define rall(a) (a).rbegin(), (a).rend()
  13. #define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
  14. #define present(c,x) ((c).find(x) != (c).end())
  15. #define cpresent(c,x) (find(all(c),x) != (c).end())
  16. #define what_is(x) cout << #x << " is: " << x << endl;
  17. #define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
  18.  
  19. #define bitcount(a) __builtin_popcount(a) // count set bits
  20. #define lzcount(x) __builtin_clz(x) // count leading zeros in binary representation of number
  21. #define tzcount(x) __builtin_ctz(x) // count trailing zeros in binary representation of number
  22.  
  23. #define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  24.  
  25. typedef long long ll;
  26. typedef long double lld;
  27. const ll MOD = 1e9+7;
  28. const lld PI = acos(-1.0);
  29.  
  30. template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
  31. template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
  32. template<typename T> T fast_power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
  33. template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
  34. template<typename X> inline X sqr(const X& a) { return a * a; }
  35. template<typename T> inline string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; }
  36.  
  37. //inline ll mod(ll x,ll n) {if (x < n) return x; if (x >= n) return x - n;}
  38. //ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M,only if M is prime
  39. //ll add(ll a,ll b,ll M) { return mod(( mod(a,M ) + mod(b,M )),M); }
  40. //ll sub(ll a, ll b,ll M) { return mod((mod(a,M ) + M - mod(b,M )),M); }
  41. //ll mult(ll a,ll b,ll M) { return mod(( mod(a,M)*mod(b,M) ),M) ; }
  42. //bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;}
  43.  
  44. ll exgcd(ll a, ll b, ll &x, ll &y){ int g = a; x = 1, y = 0; if (b) g = exgcd(b, a % b, y, x), y -= a / b * x; return g; }
  45.  
  46. ll inv(ll a, ll m) { ll x, y; exgcd(a, m, x, y); return (x + m) % m; }
  47.  
  48. int dx[] = {1, -1, 0, 0};
  49. int dy[] = {0, 0, 1, -1};
  50.  
  51. typedef vector<int> vi;
  52. typedef vector<ll> vl;
  53. typedef pair<int,int> pii;
  54. typedef pair<ll,ll> pll;
  55.  
  56. /* -------------------------------Main Code------------------------------- */
  57. ll ans;
  58. ll n,h;
  59. vi happy(25),happy1(25);
  60.  
  61. void dfs(ll frs, ll sec, ll id){
  62. if(id==n+1){
  63. if(frs>=h && sec>=h) ans++;
  64. return;
  65. }
  66. dfs(frs+happy[id],sec,id+1);
  67. dfs(frs,sec+happy1[id],id+1);
  68. dfs(frs+happy[id],sec+happy1[id],id+1);
  69. }
  70.  
  71.  
  72. int main(){
  73. FAST
  74. int T;cin>>T;
  75. for(int t=1;t<=T;t++){
  76. cin>>n>>h;
  77. for(int i=1;i<=n;i++) cin>>happy[i];
  78. for(int i=1;i<=n;i++) cin>>happy1[i];
  79. ans = 0LL;
  80. dfs(0LL,0LL,1LL);
  81. cout<<"Case #"<<t<<": "<<ans<<endl;
  82. }
  83. return 0;
  84. }
Success #stdin #stdout 0s 4536KB
stdin
2
2 3
1 2
3 3
2 5
2 2
10 30
stdout
Case #1: 3
Case #2: 0