设为首页 加入收藏

TOP

poj 3400 Dropping the stones
2015-07-20 17:59:39 来源: 作者: 【 】 浏览:2
Tags:poj 3400 Dropping the stones
//next_permutation全排列
# include 
  
   
# include 
   
     # include 
    
      using namespace std; struct node { int w; int v; }; struct node a[10010]; int max1(int x,int y) { return x>y?x:y; } int main() { int i,n,d,flag,x1,y1,ans,max; int t[10010]; while(~scanf("%d%d",&n,&d)) { for(i=0;i
     
      y1+d) flag=0; } else { y1+=a[t[i]].w; ans+=a[t[i]].v; if(y1>x1+d) flag=1; } } max=max1(max,ans); }while(next_permutation(t,t+n)); printf("%d\n",max); } return 0; }
     
    
   
  

 

 

 
 
 



// dfs
# include 
  
   
# include 
   
     # include 
    
      using namespace std; struct node { int w; int v; }; struct node a[10010]; int n,d,maxa; int vis[10010]; int max1(int x,int y) { return x>y?x:y; } void dfs(int w1,int w2,int v2,int ans,int flag) { if(ans==n) { maxa=max1(maxa,v2); return ; } else { for(int i=0;i
     
      d+w2) { dfs(w1,w2+a[i].w,v2+a[i].v,ans+1,0); } else if(flag&&w1<=d+w2) { dfs(w1+a[i].w,w2,v2,ans+1,1); } else if(!flag&&w2>d+w1) { dfs(w1+a[i].w,w2,v2,ans+1,1); } else if(!flag&&w2<=d+w1) { dfs(w1,w2+a[i].w,v2+a[i].v,ans+1,0); } vis[i]=0; } } } return ; } int main() { while(~scanf("%d%d",&n,&d)) { for(int i=0;i
      
       

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1442 Black Box(优先队列) 下一篇HDU 4883 TIANKENG’s restaurant..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: