#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int num;
int a[4],x;
const int inf=1<<10;
// 括号改变的运算符的优先级所以
//a@b@c@d 符号的全排列有 3!种可能 由于数字可以调换 ((a@b)@c) @d 等价于 a @ ((b@c)@d ) 要想使(i,j,k,l) 的优先级为 a @ ((b@c)@d ) 等价于 j,k,l,i 在 ((a@b)@c) @d 所以这种情况保留一个就好
int calc(int op,int b,int c)
{
switch(op)
{
case 1: return b+c;
case 2: return b-c;
case 3: return b*c;
case 4: if(c!=0&&b%c==0) return b/c;
else return inf;
}
}
bool fun1() // ((a@b)@c)@d
{
int i,j,k;
int k1,k2,ans;
for(i=1;i<=4;i++)
{
k1=calc(i,a[0],a[1]);
if(k1==inf) continue;
for(j=1;j<=4;j++)
{
k2=c
hdu 1427 24点暴力dfs
最新推荐文章于 2020-04-03 14:30:30 发布
点击打开链接#include #include #include using namespace std;int num;int a[4],x;const int inf=1<<10; // 括号改变的运算符的优先级所以 //a@b@c@d 符号的全排列有 3!种可能 由于数字可以调换 ((a@b)@c) @d 等价于 a @ ((b@c)@d
摘要由CSDN通过智能技术生成