hdu 2510 符号三角形 (DFS+打表)
符号三角形
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 811 Accepted Submission(s): 403
+ + - + - + +
+ - - - - +
- + + + -
- + + -
- + -
- -
+
这题还比较好吧,开始写了代码发现一定会超时,后来看了别人的解法再想想,可以打表解决,小菜的dfs一般,解24时要好几分钟...
还有题目加减号的情况和异或一样,于是用01表示方便计算。
#include<stdio.h>
#include<string.h>
int n,cnt,m;
int c[];
int judge(int c0[])
{
int cc=;
int s[];
for(int i=;i<n;i++){
s[i]=c0[i];
if(c0[i]) cc++;
}
for(int i=;i<n;i++){
for(int j=;j<n;j++) s[j]=c0[j];
for(int j=;j<n-i-;j++)
if(c0[j]=s[j]^s[j+]) cc++;
}
if(cc==m) return ;
return ;
}
void dfs(int id)
{
if(id==n){
cnt+=judge(c);return;
}
c[id]=;
dfs(id+);
c[id]=;
dfs(id+);
return;
}
int main(void)
{
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
while(scanf("%d",&n)!=EOF)
{
memset(c,,sizeof(c));
m=(n+)*n/;
if(m%){ //小剪枝
printf("%d %d\n",n,);
continue;
}
m/=;
cnt=;
dfs();
printf("%d %d\n",n,cnt);
}
return ;
}
/* */
求得解后打表
#include<stdio.h>
int ans[]={,,,,,,,,,,,,,,,,,,,,,,,,};
int main(void)
{
int n;
while(scanf("%d",&n),n)
{
printf("%d %d\n",n,ans[n]);
}
return ;
}
hdu 2510 符号三角形 (DFS+打表)的更多相关文章
- HDU 2510 - 符号三角形
DFS后打表 #include <iostream> using namespace std; ,,,,,,,,,,,,,,,,,,,,,,,,}; int main() { int n; ...
- HDU 2563 统计问题 (DFS + 打表)
统计问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- ACM: HDU 2563 统计问题-DFS+打表
HDU 2563 统计问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u HDU 2 ...
- 【HDOJ】2510 符号三角形
暴力打表. #include <cstdio> ]={,,,,,,,,,,,,,,,,,,,,,,,,}; int main() { while (scanf("%d" ...
- 符号三角形(hdu 2510 搜索+打表)
符号三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 2586 How far away(dfs+邻接表)
How far away [题目链接]How far away [题目类型]dfs+邻接表 &题意: 题目大意:一个村子里有n个房子,这n个房子用n-1条路连接起来,接下了有m次询问,每次询问 ...
- 符号三角形_hdu_2510(深搜).java
http://acm.hdu.edu.cn/showproblem.php?pid=2510 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- 符号三角形——F
F. 符号三角形 Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: Java class name: 符号 ...
- code vs 3376 符号三角形
3376 符号三角形 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 如下图是由14个“+”和14个“-”组 ...
随机推荐
- jQuery选择器与事件学习笔记
层次选择器: $("div li")获取div下的所有li元素(后代.子.子的子......) $("div>li")获取div下的直接li子元素. ...
- 解题:在下面画线的地方填任何代码,使得最终输出 'hello world',至少写五个不同思路的方案
今天(已经好些天前了...),群里面(JS前端开发跳板6群[81501322])有个群友问了这样一个问题. 如题:在下面画线的地方填任何代码,使得最终输出 'hello world',至少写五个不同思 ...
- Linux实战教学笔记15:用户管理初级(下)
第十四节 用户管理初级(下) 标签(空格分隔): Linux实战教学笔记-陈思齐 ---更多资料点我查看 1,用户查询相关命令id,finger,users,w,who,last,lastlog,gr ...
- 使用poi将excel转换为html,适用本身有导出excel的而现在需要添加网页打印的功能
PoiExcelToHtmlUtil.java import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.hssf.usermod ...
- Redis数据库 : python与java操作redis
redis 包 from redis import * 连接: r = StrictRedis(host='localhost', port='6379') 读写:r.set('key','value ...
- PHP 多参数方法的重构
假设我们要完成一个保存文章的功能,如果采用函数编程的方式,大概会是下面这个样子: <?php function saveArticle($title, $content, $categoryId ...
- Ubuntu下安装libpcap+测试安装
1.从ftp://ftp.gnu.org/gnu/下载flex.bison.GNU M4.libpcap安装包,具体的链接分别如下: flex下载:http://flex.sourceforge.ne ...
- python web框架的介绍
随着互联网的兴起,web开发变得愈发的重要.Python作为当前火热的语言, 其中的web开发框架可以说是百花齐放,下面聊一聊这些框架. 一: 基于Python的代表性Web框架 Django Dja ...
- python系列3之内置函数和文件操作
目录 自定义函数 内置函数 文件的操作 练习题 一. 自定义函数 1. 函数的创建 函数的创建 1.def关键字 2.函数名+() 3.冒号 4.缩进 5. return返回值,可以不写,默认的返回值 ...
- Sqlite客户端的使用
打开一个数据库sqlite3 ${databaseName} 查看当前打开的数据库.database 查看当前打开的数据库中的表.table 查看指定表结构(实际输出是建表语句).schema ${t ...