01bag problem measure1:most easiest way to find the answer.measure2:use the easier way to solve
2018-03-23 16:10
477 查看
i travel the whole binary tree.
measure2:#include<iostream> #include<stdio.h> #define Max_N 100 using namespace std; int res=0,Max=0; int N,W; int t[Max_N][2]; void fun(int i,int j) { if(i==N) { if(res>Max&&j>=0) { Max=res; printf("res is %d\n",res); } } else { res+=t[i][1]; fun(i+1,j-t[i][0]); res-=t[i][1]; fun(i+1,j); } } int main() { scanf("%d%d",&N,&W); for(int i=0;i<N;i++) { scanf("%d%d",&t[i][0],&t[i][1]); } fun(0,W); printf("the final result is %d\n",Max); return 0; }
#include<iostream> #include<stdio.h> #define Max_N 100 using namespace std; int res=0,Max=0; int N,W; int t[Max_N][2]; void fun(int i,int j) { if(i==N) { if(res>Max&&j>=0) { Max=res; printf("res is %d\n",res); } } else { res+=t[i][1]; fun(i+1,j-t[i][0]); res-=t[i][1]; fun(i+1,j); } } int main() { scanf("%d%d",&N,&W); for(int i=0;i<N;i++) { scanf("%d%d",&t[i][0],&t[i][1]); } fun(0,W); printf("the final result is %d\n",Max); return 0; }
measure2:#include<iostream> #include<stdio.h> #define Max_N 100 using namespace std; int res=0,Max=0; int N,W; int t[Max_N][2]; void fun(int i,int j) { if(i==N) { if(res>Max&&j>=0) { Max=res; printf("res is %d\n",res); } } else { res+=t[i][1]; fun(i+1,j-t[i][0]); res-=t[i][1]; fun(i+1,j); } } int main() { scanf("%d%d",&N,&W); for(int i=0;i<N;i++) { scanf("%d%d",&t[i][0],&t[i][1]); } fun(0,W); printf("the final result is %d\n",Max); return 0; }
相关文章推荐
- The way to solve download android source problem.
- 在线平互动台活动启动《Discover How to Make the Computer Easier to Use with Windows Vista》
- why not use the following way to generate the CSV file?
- The Best Way to Use a 32-Bit DLL Library in a 64-Bit Platform
- "How to use QThread in the right way (Part 1)"
- Use the BFS to solve the equation problems(Case : hdu 4403 )
- eclipse创建Adnroid虚拟机提示:XXXX目录.avd is in the way. Use --force if you want to overwrite.
- An easier way to register the Assemblies' Instrumentation In Enterprise Library[转]
- xargs: unmatched double quote; by default quotes are special to xargs unless you use the -0 option
- To use the default BatchConfigurer the context must contain no more thanone DataSource, found 2
- the command 'vim' and how to use it
- QPixmap: It is not safe to use pixmaps outside the GUI thread原因
- ubuntu source for caffe reference to solve the problem of the LIB
- [howto] General 5.10 - HowTo: Speed up ubuntu boot process - the way you can feel it. - updated
- Notes on how to use Webots, especially how to make a robot fly in the air
- Android studio 3.0.1版本出现的问题: Please select at least one of the signature versions to use
- How to use "vi" edit the docs or source code files
- 插入mysql语句报错:1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
- java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with ...
- java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with this activity