Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- problem Codeforces 306 (div 2) B
- */
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- #define si(n) scanf("%d",&n)
- int main()
- {
- int n,l,r,x,ans=0;
- si(n);si(l);si(r);si(x);
- int arr[n],i;
- for(i=0;i<n;i++)si(arr[i]);
- int tot=(1<<n),j;
- for(i=0;i<tot;i++){
- if(__builtin_popcount(i)<2)
- continue;
- int mn=1000000000,mx=-1000000000,jog=0;
- for(j=0;j<n;j++){
- if(i&(1<<j)){
- mn=min(mn,arr[j]);
- mx=max(mx,arr[j]);
- jog+=arr[j];
- }
- }
- if(mx-mn>=x && jog>=l && jog<=r)
- ans++;
- }
- cout<<ans<<endl;
- return 0;
- }
- /*
- lightoj : 1011 - Marriage Ceremonies
- dp with bitmask
- */
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- using namespace std;
- #define si(n) scanf("%d",&n)
- int arr[20][20],n,dp[(1<<17)][20];
- int go(int r,int msk){
- int i;
- if(r==n)
- return 0;
- int &ref=dp[msk][r];
- if(ref != -1)
- return ref;
- for(i=0;i<n;i++){
- if(!(msk & (1<<i))){
- ref=max(ref,go(r+1,msk^(1<<i))+arr[r][i]);
- }
- }
- return ref;
- }
- int main()
- {
- int t,i,j;
- //cout<<(1<<20)<<endl;
- //freopen("input.txt","r",stdin);
- si(t);
- for(int cs=1;cs<=t;cs++){
- memset(dp,-1,sizeof(dp));
- si(n);
- for(i=0;i<n;i++){
- for(j=0;j<n;j++)
- si(arr[i][j]);
- }
- int ans=go(0,0);
- printf("Case %d: %d\n",cs,ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement