D - Twenty-four point

Given four numbers, can you get twenty-four through the addition, subtraction, multiplication, and division? Each number can be used only once.

Input

The input consists of multiple test cases. Each test case contains 4 integers A, B, C, D in a single line (1 <= A, B, C, D <= 13).

Output

For each case, print the “Yes” or “No”. If twenty-four point can be get, print “Yes”, otherwise, print “No”.

Sample Input
2 2 3 9
1 1 1 1 
5 5 5 1
Sample Output
Yes
No
Yes
Hint

For the first sample, (2/3+2)*9=24.

给你四个数,每个数使用且仅能使用一次,问是否能得到24;

#include
#include
#include
#include
using namespace std;
double a[4];bool flag;
bool den(double a,double b)
{
    if(fabs(a-b)<=1e-10)
        return true;
    return false;
}
void dfs(int t)
{
    if(flag||(t==1&&den(a[0],24)))
    {
        flag=true;return;
    }
    for(int i=0;i>a[0]>>a[1]>>a[2]>>a[3])
    {
        flag=false;
        dfs(4);
        printf("%s\n",flag?"Yes":"No");
    }
    return 0;
} 



你可能感兴趣的:(dfs)