SGU 157.Patience
简单的搜索,在n>10时,要打表
code:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 20, N = 14;
int n, p[maxn], ans = 0;
void dfs (int emp)
{
int i, j, p0[maxn], z = 0;
memcpy (p0, p, sizeof (p) );
ans++;
for (i = N - n; i < N; i++)
{
if (p[i] == p[i + 1] - 1)
swap (p[i + 1], p[emp]), dfs (i + 1);
memcpy (p, p0, sizeof (p) );
}
}
int main()
{
int i;
for (i = 1; i < N; i++)
p[i] = i;
p[N] = 0;
scanf ("%d", &n);
if (n == 11) ans = 1548222;
else if (n == 12) ans = 12966093;
else if (n == 13) ans = 118515434;
else dfs (14);
printf ("%d", ans);
return 0;
}
SGU 157.Patience的更多相关文章
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- POJ2794 Double Patience[离散概率 状压DP]
Double Patience Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 694 Accepted: 368 Cas ...
- The last packet successfully received from the server was 2,926,157 milliseconds ago. The last packet sent successfully to the server was 2,926,158 milliseconds ago. is longer than the server configured value of 'wait_timeout'. 解决办法
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully rec ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- ✡ leetcode 158. Read N Characters Given Read4 II - Call multiple times 对一个文件多次调用read(157题的延伸题) --------- java
The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
随机推荐
- C# 加密解密(DES,3DES,MD5,Base64) 类
public sealed class EncryptUtils { #region Base64加密解密 /// <summary> ...
- 在ASP.NET MVC中对手机号码的验证
在ASP.NET MVC中,可以使用RegularExpression特性来验证手机号码. public class Customer { [Required(ErrorMessage = " ...
- Java基础(十一)常用类总结(一)
这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...
- Java第一次写的流布局图形界面,留个纪念
package jisuanqi; import java.awt.*; public class MyFrame extends Frame{ //继承Frame类 public MyFrame() ...
- hdu 4472 Count(递推即dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 代码: #include <cstdio> #include <cstring ...
- Centos 6.4 openNebula4
我们实验室的 OpenNebula 3.2 已经很稳定的运行了两年,除了开头一个月不熟悉这套云计算软件有点乱.容易犯错外接下来的时间里都很稳定,期间还包括一次防火演习(突然拉闸似断电)和安全检查(计划 ...
- mysql 引擎区分
MySQL常用的存储引擎为MyISAM.InnoDB.MEMORY.MERGE,其中InnoDB提供事务安全表,其他存储引擎都是非事务安全表. MyISAM是MySQL的默认存储引擎.MyISAM不支 ...
- Maven学习总结(1-10)
Maven学习总结(1-10) 本文转自 孤傲苍狼 博客,讲解精炼易懂,适合入门,链接及截图如下 http://www.cnblogs.com/xdp-gacl/tag/Maven%E5%AD%A6% ...
- [置顶] UITableViewCell
UITableViewCellStyle: 四种Cell类型. UITableViewCellSeparatorStyle 分割线类型.(group三种,plain两种) UITableViewCel ...
- Hibernate学习之对象持久化
1. 对象持久化 对象的持久化就是把内存中对象形式的业务数据,转换成数据库中的关系数据形式的业务数据.广义理解,对象的持久化还包括内存与关系数据库之交换业务数据的各种操作. 2. 对象持久化模式 1 ...