为什么RE??递归栈溢出吗?本地运行良好
by Ehrgeiz @ 2018-10-15 16:30:11
@[Ehrgeiz](/space/show?uid=57545)
freopen 去掉试试看
by yeshuo2018 @ 2018-10-16 19:30:01
// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rg register
#define il inline
using namespace std;
int point[10][10]={{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 6, 6, 6, 6, 6, 6, 6, 6, 6}, {0, 6, 7, 7, 7, 7, 7, 7, 7, 6}, {0, 6, 7, 8, 8, 8, 8, 8, 7, 6}, {0, 6, 7, 8, 9, 9, 9, 8, 7, 6}, {0, 6, 7, 8, 9, 10, 9, 8, 7, 6}, {0, 6, 7, 8, 9, 9, 9, 8, 7, 6}, {0, 6, 7, 8, 8, 8, 8, 8, 7, 6}, {0, 6, 7, 7, 7, 7, 7, 7, 7, 6}, {0, 6, 6, 6, 6, 6, 6, 6, 6, 6}};
int ans=-1, a[10][10], base;
bool h[10][10], l[10][10], g[10][10];
il int max(int a, int b){return a>b?a: b;}
int Part(int i, int j){return (i-1)/3*3+(j+2)/3;}
void Fill(int i, int j, int col){h[i][col]=l[j][col]=g[Part(i, j)][col]=true;}
void Ret(int i, int j, int col){h[i][col]=l[j][col]=g[Part(i, j)][col]=false;}
struct Zero{int num, cnt;}o[10];
il int cmp(Zero a, Zero b){return a.cnt<b.cnt;}
void dfs(int now, int y, int sum){
if(now>9){ans=max(ans, sum); return;}
int x=o[now].num, next=now, yy=y+1;
if(y==9)yy=1, ++next;
if(a[x][y]){dfs(next, yy, sum); return;}
for(int i=1; i<=9; ++i)
if(!h[x][i]&&!l[y][i]&&!g[Part(x, y)][i]){
a[x][y]=i, Fill(x, y, i);
dfs(next, yy, sum+point[x][y]*i);
a[x][y]=0, Ret(x, y, i);
}
}
int main(){
for(int i=1; i<=9; ++i){
o[i].num=i;
for(int j=1; j<=9; ++j){
scanf("%d", &a[i][j]);
if(!a[i][j])++o[i].cnt;
else Fill(i, j, a[i][j]), base+=point[i][j]*a[i][j];
}
}
sort(o+1, o+10, cmp), dfs(1, 1, 0);
~ans?printf("%d\n", ans+base): puts("-1");
}
by yeshuo2018 @ 2018-10-16 19:30:12
AC代码
by yeshuo2018 @ 2018-10-16 19:30:24
@[yeshuo2018](/space/show?uid=122578) 交的时候没带freopen
by Ehrgeiz @ 2018-10-16 19:36:35
@[Ehrgeiz](/space/show?uid=57545)
我交上去没有RE啊
by yeshuo2018 @ 2018-10-16 19:38:44