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. dmp文件导入

    dmp文件导入 1,打开“开始”-->输入cmd—> sqlplus log: 2,输入 conn / as sysdba管理员账户登录: 3,需要创建表空间,如果我们知道需要导入的数据库 ...

  2. jQuery实现用户注册的表单验证

    用户注册的表单往往是需要进行验证的,否则会有一些不否合规则的数据入库,后果会不堪设想,本文通过jquery来实现. <html>  <head>  <meta chars ...

  3. Nginx启动、停止与平滑重启

    如何启动Nginx:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 停止Nginx:可以发送向通信号给Nginx主进程的 ...

  4. 相同的 birthday

    Description Sometimes some mathematical results are hard to believe. One of the common problems is t ...

  5. vim中执行shell命令小结

    vim中执行shell命令,有以下几种形式 1):!command 不退出vim,并执行shell命令command,将命令输出显示在vim的命令区域,不会改变当前编辑的文件的内容 例如:!ls -l ...

  6. C#基础原理拾遗——面试都爱问的委托和事件(纠正)

    这篇博客是我昨天写的,文中的观点有些问题,后经过网友留言和个人学习发现错误,原文还是保留,更改补在后面,不怕贻笑大方,唯恐误人子弟.不知道还能不能放在首页,让被误导的同学再被反误导一次. 一.原文 几 ...

  7. JSTL标签总结

    一.JSTL简介: 1.JSP标准标签库JSTL(JSP Standard Tag Library)是一个JSP标签集合,它封装了JSP应用的通用核心功能. 2.JSTL支持通用的.结构化的任务.比如 ...

  8. android开发获取屏幕高度和宽度

    宽度:getWindowManager().getDefaultDisplay().getWidth(); 高度:getWindowManager().getDefaultDisplay().getH ...

  9. [CF]codeforces round 369(div2)

    *明早起来再贴代码 A [题意] 给定n*5的方格 将横向的相邻两个变成+输出 [题解] ... B [题意] 一个n*n的正整数矩阵,有且仅有一个数为0 ,在这个位置填上一个数,使得每一列的和 每一 ...

  10. 基于Pre-Train的CNN模型的图像分类实验

    基于Pre-Train的CNN模型的图像分类实验  MatConvNet工具包提供了好几个在imageNet数据库上训练好的CNN模型,可以利用这个训练好的模型提取图像的特征.本文就利用其中的 “im ...