https://code.google.com/codejam/contest/4214486/dashboard#s=p0

排列组合。DP递推式,如下代码。dp[m][n]表示长度为n的字符串里有m个字符,那么可以先用m-1个字符拼一个长度为n-1的字符串,然后再C(n,1)里面挑一个放最后一个字符;这是最后一种字符是一个的情况,后面还有两个三个等等。所以代码如下:

要注意的是,可以先计算组合数combination[n][m],用C(n,m)=C(n−1,m)+C(n−1,m−1)来算。

/*
f[i][n] = f[i-1][n-1]*C(n,1) + f[i-1][n02]*C(n,2) + ... + f[i-1][i-1] * C(n, n-(i-1));
*/ #include <iostream>
#include <vector>
using namespace std; int base = 1000000007;
typedef long long llong; llong combination[101][101]; void buildCombination() {
for (int i = 0; i <= 100; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0) {
combination[i][j] = 1;
} else {
combination[i][j] = (combination[i-1][j] + combination[i-1][j-1]) % base;
}
}
}
} llong solve(int m, int n) {
vector<vector<llong> > dp;
dp.resize(m+1);
for (int i = 0; i < m+1; i++) {
dp[i].resize(n+1);
}
// i chars, len of j
for (int i = 1; i <= m; i++) {
for (int j = i; j <= n; j++) {
if (i == 1) {
dp[i][j] = 1;
continue;
}
dp[i][j] = 0;
for (int k = 1; j-k >= i-1; k++) {
dp[i][j] = (dp[i][j] + dp[i-1][j-k] * combination[j][k]) % base; }
}
}
return dp[m][n];
} int main() {
int T;
buildCombination();
cin >> T;
for (int i = 1; i <= T; i++) {
int m, n;
cin >> m >> n;
llong r = solve(m, n);
cout << "Case #" << i << ": " << r << endl;
}
return 0;
}

  

[GCJ]Password Attacker的更多相关文章

  1. Password Attacker

    Passwords are widely used in our lives: for ATMs, online forum logins, mobile device unlock and door ...

  2. 【DP】组合数字

    Password Attacker 题意就是给 M 个关键字,组合成 N 字符长度的结果,每一个关键字都必须在 N 位的字符中出现,有多少种可能结果. 范围 1 ≤ M ≤ N ≤ 100. 举例假设 ...

  3. hdu3625

    hdu3625 题意: 酒店发生一起谋杀案.作为镇上最好的侦探,您应该立即检查酒店的所有N个房间.但是,房间的所有门都是锁着的,钥匙刚锁在房间里,真是个陷阱!您知道每个房间里只有一把钥匙,并且所有可能 ...

  4. A complex 16-Level XSS Challenge

    A complex 16-Level XSS Challenge, held in summer 2014 (+1 Hidden Level) Index Level 0 Level 1 Level ...

  5. bitbar 网站攻击实验

    实验环境 https://github.com/TouwaErioH/security/tree/master/web1 Windows10 Oracle VM VirtualBox Ubuntu16 ...

  6. Spring Security(三十三):10.3 Password Encoding

    Spring Security’s PasswordEncoder interface is used to support the use of passwords which are encode ...

  7. ASP.NET OAuth Authorization - Difference between using ClientId and Secret and Username and Password

      What I don't fully understand is the use of ClientId and Secret vs Username and Password. The code ...

  8. MetInfo Password Reset Poisoning By Host Header Attack

    if we know some user's email, the we will can reset the user's email by host header attack. The atta ...

  9. 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?

    p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...

随机推荐

  1. yum最常用的命令

    yum是一个用于管理rpm包的后台程序,用python写成,可以非常方便的解决rpm的依赖关系.在建立好yum服务器后,yum客户端可以通过 http.ftp方式获得软件包,并使用方便的命令直接管理. ...

  2. 利用PowerDesigner绘制PDM生成SQL Server数据库

    PowerDesigner是个很强大的建模工具,可以利用它绘制各种图形,本文利用该工具绘制PDM,进而生成SQL Server数据库. 比如绘制一个简单的学生选课.教师授课管理系统的PDM: pk表示 ...

  3. Geoserver 相关学习

    参考资料: http://geoserver.org/ http://docs.geoserver.org/ 相关文档 http://docs.geoserver.org/stable/en/user ...

  4. Linux系统下sendmail发送邮件失败的问题

         问题是:安装完sendmail,启动服务后,发送邮件第一次发送成功,后面再次无论怎么发送都不行,换邮箱也不行.在确认我的邮件发送格式正确无误后,想到查看邮件发送日志: [root@backu ...

  5. 每日一“酷”之textwrap

    介绍:需要美观打印时,可以使用textwrap模块来格式化要输出的文本,这个模块允许通过编程提高类似段落自动换行或填充特性等功能. 1 创建实例数据 sample_text = ''' I’m ver ...

  6. linux 进程控制笔记

    进程创建 普通函数调用完成后,最多返回(return)一次,但fork/vfork会返回二次,一次返回给父进程,一次返回给子进程 父进程的返回值为子进程的进程ID,子进程的返回值为0 1.pid_t ...

  7. linux 非缓冲io笔记

    简介 在linux中,打开的的文件(可输入输出)标识就是一个int值,如下面的三个标准输入输出 STDIN_FILENO/STDOUT_FILENO/STDERR_FILENO这三个是标准输入输出,对 ...

  8. MySQL 简洁连接数据库方式

    OS  :   CentOS 6.3 DB  :  5.5.14 MySQL连接数据库的方式很多: 1.[root@db01 bin]# ./mysql -uroot -p 2.[root@db01 ...

  9. 多线程中,static函数与非static函数的区别?

    最近在学习多线程,刚入门,好多东西不懂,下面这段代码今天想了半天也没明白,希望看到的兄弟姐妹能解释下. public class NotThreadSafeCounter extends Thread ...

  10. SVN服务器搭建和使用

    SVN服务器搭建和使用 Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了,下 ...