简单的搜索,在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. 元素重叠及position定位的z-index顺序

    元素位置重叠的背景常识 (x)html文档中的元素默认处于普通流(normal flow)中,也就是说其顺序由元素在文档中的先后位置决定,此时一般不会产生重叠(但指定负边距可能产生重叠).当我们用cs ...

  2. IronPython fail to add reference to WebDriver.dll

    在使用Ironpython引用WebDriver程序集做web自动化时碰到这个问题,出问题的代码很简单,如下: import sys import clr clr.AddReferenceToFile ...

  3. WinForm------自定义YearMonthEdit组件

    转载: http://www.cnblogs.com/axing/p/3201066.html 注意: 1.需要在vs里面,添加一个YearMonthEdit组件,然后将链接里面的代码拷贝到里面 2. ...

  4. 外显子分析:cutadapt,去除序列adapter详细解析

    外显子测序时带有adapt接头,因此我们需要去除adapt接头,cutadapt的作用是去除adapt接头,一般用到如下命令: cutadapt -a AACCGGTT -o output.fastq ...

  5. python 写的http后台弱口令爆破工具

    今天来弄一个后台破解的Python小程序,哈哈,直接上代码吧,都有注释~~ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ...

  6. 【设计模式 - 19】之观察者模式(Observer)

    1      模式简介 观察者模式的介绍: 观察者模式定义了对象之间的一对多依赖,这样一来,当一个对象的状态发生改变时,它的所有依赖者都会收到通知并自动更新. 发布者(被观察者) + 订阅者(观察者) ...

  7. delphi TOpenDialog

        TOpenDialog     procedure TForm1.Button1Click(Sender: TObject);begin  with TOpenDialog.Create(ni ...

  8. [AngularJS + Webpack] Requiring CSS & Preprocessors

    Making your CSS modular is a difficult thing to do, but using Webpack makes this so much easier. By ...

  9. otg线是什么,otg线和数据线的区别介绍

    OTG是什么? OTG主要应用于各种不同的设备或移动设备间的联接,进行数据交换.USB技术的发展,使得PC和周边设备能够通过简单方式.适度的制造成本将各种数 据传输速度的设备连接在一起.上述我们的应用 ...

  10. JSF学习五Ajax

    验证username(不能有下划线)和password(不能小于六位) 1.UserBean.java package ajax; import java.io.Serializable; impor ...