[GCJ]Password Attacker
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的更多相关文章
- Password Attacker
Passwords are widely used in our lives: for ATMs, online forum logins, mobile device unlock and door ...
- 【DP】组合数字
Password Attacker 题意就是给 M 个关键字,组合成 N 字符长度的结果,每一个关键字都必须在 N 位的字符中出现,有多少种可能结果. 范围 1 ≤ M ≤ N ≤ 100. 举例假设 ...
- hdu3625
hdu3625 题意: 酒店发生一起谋杀案.作为镇上最好的侦探,您应该立即检查酒店的所有N个房间.但是,房间的所有门都是锁着的,钥匙刚锁在房间里,真是个陷阱!您知道每个房间里只有一把钥匙,并且所有可能 ...
- 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 ...
- bitbar 网站攻击实验
实验环境 https://github.com/TouwaErioH/security/tree/master/web1 Windows10 Oracle VM VirtualBox Ubuntu16 ...
- Spring Security(三十三):10.3 Password Encoding
Spring Security’s PasswordEncoder interface is used to support the use of passwords which are encode ...
- 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 ...
- 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 ...
- 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?
p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...
随机推荐
- 【Qt】QWidget、QDialog、QMainWindow的异同点【转】
简述 在分享所有基础知识之前,很有必要在这里介绍下常用的窗口-QWidget.QDialog.QMainWindow. 熟悉Qt的同学都应该知道,在新建Qt Widgets项目进行类信息选择时会碰到它 ...
- 一款jQuery仿海尔官网全屏焦点图特效代码
一款jQuery仿海尔官网全屏焦点图特效代码,带有左右箭头的jQuery焦点图切换特效. 当焦点图切换时,下方的三块小图也相对应的进行切换.并且特效还兼容头疼的IE6.赶快去和谐了它吧! 适用浏览器: ...
- 使用cookie解决微信不能存储localStorage的问题
最近在开发基于微信的Web页面时,发现有些机型不能存储信息到localStorage中,或者是页面一旦关闭,存储的信息也失效了. 于是想到用cookie来替代localStorage,存储一些简单的数 ...
- mysql手工注入
以下是mynona本人原创的,奉献给大家,不要小看数据库注入 参考: http://www.daydaydata.com/help/sql/advance/limit.html http://www. ...
- linux下查看进程内存使用情况
1. top命令--动态查看一个进程的内存使用top -d 1 -p pid [,pid ...] //设置为delay 1s,默认是delay 3s 如果想根据内存使用量进行排序,可以shift ...
- linux终端io笔记
简介 终端的两种工作模式:以行为单位的工作模式,以字符数或时间为单位自定义模式 终端判断函数: int isatty(int fd) 终端属性的获取与设置: int tcgetattr(int fd, ...
- Qt postEvent
Qt3中可以直接向线程发送消息 QThread::postEventQ4中已不支持为了模拟向线程发送消息,可以通过QObject::moveToThread后,然后再向这个QObject发送消息 ob ...
- 我只知道一点非常简单的关于MVC的验证
我只知道一些非常简单的关于MVC的验证 如题,我只知道一点非常简单的关于MVC的验证,所以如果您接触过MVC的验证,相信也就不用看了,这个且当作是学习笔记吧. 先小讲解一下他基本的五个从Model里打 ...
- Linux开机执行bash脚本
问题描述: Linux开机执行bash脚本 问题解决: (1)在 /etc/init.d文件夹中新建一个脚本myinit (2) ...
- Vim Cscope安装与使用
问题描述: Cscope是VIM适用的工具和插件,通过Cscope可以方便的获取某个函数的定义以及被那些函数调用 问题解决: (1)Cscope安装 注: ...