题目链接:hdu 5225 Tom and permutation

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll; const int maxn = 100;
const int mod = 1e9+7;
int N, ans, V[maxn + 5], A[maxn + 5];
ll S[maxn + 5], L[maxn + 5]; int query(int x) {
int ret = 0;
for (int i = 1; i < x; i++) {
if (V[i] == 0)
ret++;
}
return ret;
} int dfs(int d, int s) { if (d > N)
return 0; if (s == 0) {
ans = (ans + S[N-d+1]) % mod;
return L[N-d+1];
} else { int ret = 0; for (int i = 1; i <= A[d]; i++) {
if (V[i]) continue; V[i] = 1; int s = query(i);
ll temp = dfs(d + 1, i == A[d] ? 1 : 0);
ans = (ans + temp * s % mod) % mod; ret = (ret + temp) % mod; V[i] = 0;
} return ret;
}
} int main () {
S[1] = 0;
L[1] = 1;
for (int i = 2; i <= maxn; i++) {
S[i] = S[i-1] * i % mod+ L[i-1] * ((1LL * i * (i-1) / 2) % mod) % mod;
L[i] = L[i-1] * i % mod;
} while (scanf("%d", &N) == 1) {
ans = 0;
memset(V, 0, sizeof(V)); for (int i = 1; i <= N; i++)
scanf("%d", &A[i]); dfs(1, 1);
printf("%d\n", ans);
}
return 0;
}

hdu 5225 Tom and permutation(回溯)的更多相关文章

  1. HDU 5224 Tom and paper(最小周长)

    HDU 5224 Tom and paper(最小周长) Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d &a ...

  2. HDU 5868 Different Circle Permutation(burnside 引理)

    HDU 5868 Different Circle Permutation(burnside 引理) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=586 ...

  3. 组合数(Lucas定理) + 快速幂 --- HDU 5226 Tom and matrix

    Tom and matrix Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analy ...

  4. HDU 5113 Black And White 回溯+剪枝

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5113 Black And White Time Limit: 2000/2000 MS (Java/ ...

  5. hdu 5224 Tom and paper

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5224 Tom and paper Description There is a piece of pa ...

  6. [HDU 1016]--Prime Ring Problem(回溯)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...

  7. [HDU 2553]--N皇后问题(回溯)/N皇后问题的分析

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2553 N皇后问题 Time Limit: 2000/1000 MS (Java/Others)     ...

  8. HDU 5225 枚举

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5225 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  9. HDU 2553 n皇后问题(回溯法)

     DFS Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description ...

随机推荐

  1. 常见的XSS攻击代码

    第一类: <tag on*=*/> 在html标签事件中触发,典型的是on*事件,但是这种触发模式的缺陷在于不能直接触发所以更多的需要配合使用. eg: 1.使html元素占据整个显示页面 ...

  2. NFC (Near Filed Communication)

    NFC的用途:近场通信(Near Field Communication,NFC),又称近距离无线通信,是一种短距离的高频无线通信技术,允许电子设备之间进行非接触式点对点数据传输(在十厘米内)交换数据 ...

  3. 在微信端使用video标签,播放结束会出现QQ浏览器推荐视频的解决办法(vue)

    会出现播放结束显示QQ浏览器推荐视频的原因:(我是vue的项目,而且我是新手,只是单纯的给大家分享一个方法,代码比较low请自动忽略) 因为在x5(QQ浏览器)内核中,把video标签劫持了,只要是检 ...

  4. Docker安装Mysql数据库容器(zz)

    zz自:http://blog.csdn.net/chengxuyuanyonghu/article/details/54380032 1.下载mysql的镜像: sudo docker pull m ...

  5. [Redis源码阅读]sds字符串实现

    初衷 从开始工作就开始使用Redis,也有一段时间了,但都只是停留在使用阶段,没有往更深的角度探索,每次想读源码都止步在阅读书籍上,因为看完书很快又忘了,这次逼自己先读代码.因为个人觉得写作需要阅读文 ...

  6. [转载] Hive与HBase的联系与区别

    转载自http://blog.csdn.net/wangmuming/article/details/23954527和http://www.cnblogs.com/justinzhang/p/427 ...

  7. Google Python编程规范

    http://pan.baidu.com/s/1dD1Ra7J 其他语言的编程风格: http://zh-google-styleguide.readthedocs.org/en/latest/

  8. C#值参数和引用参数

    一.值参数 未用ref或out修饰符声明的参数为值参数. 使用值参数,通过将实参的值复制到形参的方式,把数据传递到方法.方法被调用时,系统做如下操作. 在栈中为形参分配空间. 复制实参到形参. 值参数 ...

  9. riot.js教程【六】循环、HTML元素标签

    前文回顾 riot.js教程[五]标签嵌套.命名元素.事件.标签条件 riot.js教程[四]Mixins.HTML内嵌表达式 riot.js教程[三]访问DOM元素.使用jquery.mount输入 ...

  10. SpringMVC 快速入门

    SpringMVC 快速入门 SpringMVC 简介 SpringMVC是 Spring为展示层提供的基于Web MVC设计模式的请求驱动类型的轻量级Web框架,它的功能和Struts2一样.但比S ...