# 题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1427

# AC代码

```#include<bits/stdc++.h>
using namespace std;
int flag=0;
int card[5];
char s[3];
void convert(int i){
if(s[0]=='A') card[i]=1;
else if(s[0]=='J') card[i]=11;
else if(s[0]=='Q') card[i]=12;
else if(s[0]=='K') card[i]=13;
else if(s[0]=='1'&&s[1]=='0') card[i]=10;//容易忘！！！
else card[i]=s[0]-'0';
}
void dfs(int sum,int step,int tmp){
if(flag) return ;
if(step==4){//结束前要将前半段与后半段拼接
if(sum+tmp==24 || sum-tmp==24 || sum*tmp==24) flag=1;
if(tmp!=0&&sum%tmp==0&&sum/tmp==24) flag=1;
return ;
}
//前后半段拼接
dfs(sum+tmp,step+1,card[step+1]);
dfs(sum-tmp,step+1,card[step+1]);
dfs(sum*tmp,step+1,card[step+1]);
if(tmp!=0&&sum%tmp==0) dfs(sum/tmp,step+1,card[step+1]);
//新数字与后半段拼接
dfs(sum,step+1,tmp+card[step+1]);
dfs(sum,step+1,tmp-card[step+1]);
dfs(sum,step+1,tmp*card[step+1]);
if(tmp%card[step+1]==0) dfs(sum,step+1,tmp/card[step+1]);
}

int main(){
while(cin>>s){
convert(1);
for(int i=2;i<=4;i++){
cin>>s;
convert(i);
}

flag=0;

sort(card+1,card+5);
do{
dfs(card[1],2,card[2]);
}while(next_permutation(card+1,card+5)&&!flag);//全排列

if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}```