| 比赛 | 
    近期练习题回顾 | 
    评测结果 | 
    AAAAAAAAAA | 
    | 题目名称 | 
    逃离农场 | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    @@@ | 
    运行时间 | 
    0.172 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    13.66 MiB  | 
    | 提交时间 | 
    2018-10-25 10:13:26 | 
显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
int n,ans;
int a[50];
bool cheak(int x,int y)
{
	while(x > 0&& y > 0)
	{
		if(x%10 + y%10 >= 10)
		{
			return 0;
		}
		x-=(x%10);x/=10;
		y-=(y%10);y/=10;
	}
	return 1;
}
void dfs(int x,int w,int ass)
{
	if(x==n+1)return;
	if(cheak(w,a[x]))
	{
		ans = max(ans,ass);
		dfs(x+1,w+a[x],ass+1);
		dfs(x+1,w,ass);
	}
	else
		dfs(x+1,w,ass);
}
int main()
{
	freopen("cowescape.in","r",stdin);
	freopen("cowescape.out","w",stdout);
	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	dfs(0,0,0);
	cout << ans <<endl;
	//cout << cheak(7311,9) << endl;
	return 0;
}