简单的搜索,在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的更多相关文章

  1. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  2. POJ2794 Double Patience[离散概率 状压DP]

    Double Patience Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 694   Accepted: 368 Cas ...

  3. 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 ...

  4. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  5. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  6. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  7. 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 ...

  8. ✡ 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 ...

  9. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

随机推荐

  1. 2015第42周六Pgsql全文索引

    全文搜索通常也就是文本搜索,它可以提供满足查询的识别自然语言的能力,并且任意性地通过相关性查询进行排序.搜索最常见的类型就是找到所有包含给定的查询术语的记录,并且以相似性的查询顺序返回它们. 对于普通 ...

  2. Linux学习笔记27——共享内存

    一 共享内存 共享内存是由IPC为进程创建的一个特殊的地址范围,它将出现在该进程的地址空间中.其他进程可以将同一段共享内存连接到它们自己的地址空间中,所有进程都可以访问共享内存中的地址.如果某个进程向 ...

  3. MVC 5 App 通过 Facebook OAuth2 登陆(Sign-on)的问题

    今天做了下MVC 5 App通过Google, Twitter, Linkedin 和 Facebook进行登录的例子, 算是对Asp.net Identity的一个入门,做的过程中发现了如下的问题, ...

  4. Ethernet & IEEE 802.3 802.X 802.1ag-MEP

    ISO/IEC 7498标准,它定义了网络互联的7层框架,也就是开放式系统互连参考模型(OSI模型). 交换机好比是邻近的街道,而路由器则是街道的交汇点. (交换机第二层,即数据链路层,也有四层,七层 ...

  5. 简单粗暴地理解 JavaScript 原型链

    尼玛!你特么也是够了! Don’t BB! Show me the code! function Person (name) { this.name = name; } function Mother ...

  6. Installing scikit-learn

    Installing scikit-learn http://scikit-learn.org/stable/install.html Installing scikit-learn There ar ...

  7. Linux2.6内核--中断线被关闭的情况

          中断系统是现代操作系统中不可获取的一个子系统,它由硬件主动触发并发送到CPU,最后由内核调用中断处理程序处理中断.       那么中断有时候需要关闭,这是为什么呢?       一般分为 ...

  8. thinkphp xml编码函数

    /** * XML编码 * @param mixed $data 数据 * @param string $root 根节点名 * @param string $item 数字索引的子节点名 * @pa ...

  9. DOS命令创建以日期为文件名的任务计划TXT文件

    因为每天早上都要做计划,所以做了个批处理文件来创建任务计划TXT文件 文件内容展示如下: 2013/07/09 周二 今日任务: 1. 2. 待办任务: 1. 2. 出现问题: 解决办法: 出现问题: ...

  10. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...