| 记录编号 | 41358 | 评测结果 | AWAAAAAAAAA | 
    
        | 题目名称 | 946.待售干草 | 最终得分 | 90 | 
    
        | 用户昵称 |  ok | 是否通过 | 未通过 | 
    
        | 代码语言 | C++ | 运行时间 | 0.069 s | 
    
        | 提交时间 | 2012-07-22 13:44:02 | 内存使用 | 0.34 MiB | 
    
    
    
    		显示代码纯文本
		
		#include <fstream>
using namespace std;
bool b[5001];
int z,n,a[5001],m=0,mo=0;
int cao()
{
	int i;
	if(m>=z)
	{
		return 0;
	}
	else
	{
		for(i=1;i<=n;i++)
		{
			if(b[i]==false&&m+a[i]<=z)
			{
				b[i]=true;
				m+=a[i];
				if(m>=mo) mo=m;
				cao();
				m=m-a[i];
			}
		}
	}
	return 0;
}
int main()
{
	int i;
	ifstream input("hay4sale.in");
    ofstream output("hay4sale.out");
	input>>z>>n;
	for(i=0;i<=5000;i++)
	{
		b[i]=false;
	}
	for(i=1;i<=n;i++)
	{
		input>>a[i];
	}
	cao();
	output<<mo<<endl;
	input.close();
    output.close();
    return 0;
}