爆搜创造性剪枝实验
来源:互联网 发布:淘宝升钻后流量下降 编辑:程序博客网 时间:2024/04/30 13:18
题目:靶形数独
各种小优化和位运算,待补充,程序并未完成,实际上优化是无止境的!
代码:
#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<cstdio>using namespace std;const int id[10][10]={0,0,0,0,0,0,0,0,0,0, 0,1,1,1,2,2,2,3,3,3, 0,1,1,1,2,2,2,3,3,3, 0,1,1,1,2,2,2,3,3,3, 0,4,4,4,5,5,5,6,6,6, 0,4,4,4,5,5,5,6,6,6, 0,4,4,4,5,5,5,6,6,6, 0,7,7,7,8,8,8,9,9,9, 0,7,7,7,8,8,8,9,9,9, 0,7,7,7,8,8,8,9,9,9};const int sc[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 a[10][10],ans;bool o=false;unsigned int xx[10],yy[10],kui[10];struct aa{int x,i;bool operator <(const aa &b) const {return x<b.x;}}t[10];struct aaa{int x,y;}pos[102];int num;int last[11][11];void dfs(int t,int now){if (t==num+1) {o=true;ans=max(ans,now);return ;} int xc=pos[t].x,yc=pos[t].y;for (int i=1;i<=9;i++)if (!(xx[xc]&(1<<i))&&!(yy[yc]&(1<<i))&&!(kui[id[xc][yc]]&(1<<i))){xx[xc]^=(1<<i);yy[yc]^=(1<<i);kui[id[xc][yc]]^=(1<<i);dfs(t+1,sc[xc][yc]*i+now);xx[xc]^=(1<<i);yy[yc]^=(1<<i);kui[id[xc][yc]]^=(1<<i);}}int main(){for (int i=1;i<=9;i++)for (int j=1;j<=9;j++) scanf("%d",&a[i][j]);for (int i=1;i<=9;i++)for (int j=1;j<=9;j++)if (a[i][j]>0){int t=a[i][j];xx[i]|=(1<<t);yy[j]|=(1<<t);kui[id[i][j]]|=(1<<t);ans+=a[i][j]*sc[i][j];}for (int i=1;i<=9;i++){for (int j=1;j<=9;j++)if (a[i][j]==0) t[i].x++;t[i].i=i;}sort(t+1,t+9+1);for (int i=1;i<=9;i++)for (int j=1;j<=9;j++) if (a[t[i].i][j]==0)pos[++num].x=t[i].i,pos[num].y=j;dfs(1,ans);if (o) printf("%d",ans);else printf("-1");return 0;}
0 0
- 爆搜创造性剪枝实验
- [NOIP 2003] 传染病控制:创造性地DFS,最优性剪枝
- 创造性生存
- poj3278(广搜剪枝)
- sticks(深搜剪枝)
- poj1465剪枝广搜
- hdu1010 深搜剪枝.
- hdu1455Sticks【深搜剪枝】
- hdu4876 暴搜剪枝
- 深搜的剪枝
- 深搜剪枝
- 剪枝
- 数据结构与算法实验题 9.1 K 歌 DFS+剪枝
- 【USACO4.1.2】栅栏的木料 爆搜剪枝优化
- BZOJ 1225: [HNOI2001] 求正整数 数论,爆搜剪枝
- 如何具有创造性
- 创造性地解决问题
- 那些睡眠的创造性
- JavaScript中的值传递和toString
- Oracle查询表名为User的表时报ORA-00903:表名无效
- 用wget命令的爬虫功能抓取网页到本地文件,然后用grep命令分析文件。
- WP8.1手机驱动安装失败,提示“INF中的服务安装段落无效”
- 1619-7 张良 十月三号总结 [连续第三天]
- 爆搜创造性剪枝实验
- Mybatis 内置 Java 类型别名与 typeHandlers
- emacs 绘制散点图
- Android获取手机型号,系统版本,App版本号等信息
- Error inflating class android.support.v4.view.ViewPager 问题的解决方法
- HashSet 详解
- Codeforces Round #375 (Div. 2)【A,B【模拟】,D【DFS】】
- shell详解八
- Leetcode解题报告:94. Binary Tree Inorder Traversal