| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
太水了!!!!附一dfs代码!!!#include <algorithm> #include <iostream> #include <sstream> #include <fstream> #include <cstring> #include <cstdlib> #include <cstring> #include <vector> #include <queue> #include <cstdio> #include <cmath> #include <string> #include <stack> #include <map> #include <new> #include <set> #define inf 0x3f3f3f3f #define M 100006 #define stop system("pause") using namespace std; int n,t; int a[M]; int mi=inf; void dfs(int s,int i){ if(s>=n){ mi=min(mi,s-n); } if(i==t+1){ return ; } dfs(s+a[i],i+1); dfs(s,i+1); } int main(){ cin>>t>>n; for(int i=1;i<=t;i++) scanf("%d",&a[i]); dfs(0,0); printf("%d\n",mi); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator