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. asp.net图片上传实例

    网站后台都需要有上传图片的功能,下面的例子就是实现有关图片上传. 缺点:图片上传到本服务器上,不适合大量图片上传. 第一.图片上传,代码如下: xxx.aspx 复制代码代码如下: <td cl ...

  2. ASP 连接 MySQL 数据库两种方法

    一般都是用myodbc来连接.首先,在系统中安装 Mysql 的ODBC数据库驱动.如安装稳定版本是3.51.下载地址是:http://dev.mysql.com/downloads/connecto ...

  3. js文本框验证

    1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafte ...

  4. selenium+python 浏览器标签页跳转 switch_to_window

    浏览器页面跳转方法记录: from selenium import webdriver import time browser = webdriver.Chrome() first_url='http ...

  5. ORACLE 11G 配置DG 报ORA-10458、ORA-01152、ORA-01110

    操作系统: Oracle Linux Server release 5.7 数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.3 ...

  6. 详解C/C++预处理器

     C/C++编译系统编译程序的过程为预处理.编译.链接.预处理器是在程序源文件被编译之前根据预处理指令对程序源文件进行处理的程序.预处理器指令以#号开头标识,末尾不包含分号.预处理命令不是C/C++语 ...

  7. andriod Kernel configuration is invalid

    error:  ERROR: Kernel configuration is invalid.         include/generated/autoconf.h or include/conf ...

  8. swift UIAlertController教程

    在iOS8中,UIAlertView与UIActionSheet都已经退休,取而代之的是UIAlertController!它的使用示范如下://弹出一个警告框,标题是“提示”,信息是“我的博客:oa ...

  9. “Microsoft Visual Studio遇到了问题,需要关闭”解决办法

    运行VS2008,打开项目,弹出错误界面 . 解决办法:将项目中的所有设计窗体关闭并保存,重新打开就OK~

  10. Android crop image size

    private void performCrop() { try { //call the standard crop action intent (the user device may not s ...