简单的搜索,在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. Bitmap 与Drawable相互转换

    Drawable 转 Bitmap import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import ...

  2. UVa11090 Going in Cycle!!

    UVa11090 Going in Cycle!! 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34650 [思路] ...

  3. JavaScript 概览 更新时间2014-0414-0837

    一些概念 DOM(文档对象模型)是HTML和XML的应用程序接口(API).DOM Level1规划文档结构:DOM Level2扩展了对鼠标和用户界面事件等的支持:DOM Level3支持了XML1 ...

  4. 对C++进行优化了的android-ndk-r6-crystax-2

    https://www.crystax.net/en/android/ndk/6?id=6 Here is customized distribution of Android NDK r6 whic ...

  5. 长沙Uber优步司机奖励政策(1月25日~1月31日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  6. Linux 下挂载硬盘的 方法

    1. 添加磁盘,查看磁盘状况 [root@db1 /]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sector ...

  7. HDU3336-Count the string(KMP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. Raspberry Pi + 3个USB摄像头 + Motion(简易监控设备配置记录1——介绍以及安装) 分类: Raspberry Pi 服务器搭建 2015-04-12 19:21 226人阅读 评论(0) 收藏

    参考: Debian官网链接 Motion官网链接 首先,参见Debian官网链接对Motion的介绍,网页中包含了所有相关依赖包,请首先确保这些依赖包的安装. Motion介绍 摘出对Motion的 ...

  9. /proc/sysrq-trigger

    立即重启计算机      echo "b" > /proc/sysrq-trigger 立即关闭计算机      echo "o" > /proc/ ...

  10. Java NIO类库Selector机制解析--转

    一.  前言 自从J2SE 1.4版本以来,JDK发布了全新的I/O类库,简称NIO,其不但引入了全新的高效的I/O机制,同时,也引入了多路复用的异步模式.NIO的包中主要包含了这样几种抽象数据类型: ...