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个“-”组 ...
随机推荐
- 17、SpringBoot------整合dubbo
SpringBoot整合Dubbo+Zookeaper 1.安装运行zookeeper (1)下载zookeeper 官网:http://zookeeper.apache.org/ (2)解压缩 (3 ...
- Hibernate无法提取结果集
原因:表结构错误或 与 映射文件不一致 org.springframework.dao.InvalidDataAccessResourceUsageException: could not extra ...
- http2.2配置
http: 超文本传输协议,工作在应用层 CentOS 6程序环境:httpd-2.2 配置文件: /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/*.con ...
- Windows下MySQL数据库的安装与关闭开机自启动
我在学习java,安装数据库时找了很多教程,现在在这里总结一下我安装数据库的过程,我安装的是mysql-5.6.42-winx64版本的. 数据官方下载地址:https://dev.mysql.com ...
- ES6笔记04-class的基本语法
JavaScript 语言中,生成实例对象的传统方法是通过构造函数. ES6 提供了更接近传统语言的写法,引入了 Class(类)这个概念,作为对象的模板.通过class关键字,可以定义类. clas ...
- tp5 使用技巧(持续更新中...)
tp5 使用技巧(持续更新中...) 1.自动写入时间 create_time和update_time 使用save方法才行,insert方法不生效,不知为何 2.过滤字段 allowfield和st ...
- 面向对象特性 - php
1.类的字段调用格式 公用字段 类内调用 $this->字段名 类外调用 $对象名->字段名 静态 类内调用 self::$字段名 类外调用 类名::$字段名 常量 类内调用 ...
- 调整图像的亮度和对比度—opencv
1.理论基础 两个参数 和 一般称作 增益 和 偏置 参数.我们往往用这两个参数来分别控制 对比度 和 亮度 . 你可以把 看成源图像像素,把 看成输出图像像素.这样一来,上面的式子就能写得更 ...
- 第三章:Web表单
感谢作者 –> 原文链接 本文翻译自 The Flask Mega-Tutorial Part III: Web Forms 这是Flask Mega-Tutorial系列的第三部分,我将告诉你 ...
- The Image Gallery Revisited
Lets apply the Best practices to the Image Gallery . /*** index.html ***/ <!DOCTYPE html> < ...