[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 ...
随机推荐
- 基础学习总结(四)--SQLite
1. SQLiteDatabase 操作SQLite数据库的类.可以执行SQL语句,对数据库进行增.删.查.改的操作.也可以进行transaction的控制.很多类对数据库的操作最终都是通过SQL ...
- .Net 将一个DataTable分解成多个DataTable
这两天遇到一个问题,我们所接触 的一个系统在导出数据到Excel的时候,产生了内存溢出的错误.原因在于数据过大,它导出是将所有数据存放在一个DataSet的一个表中,再将这个数 据集放入session ...
- mac os使用homebrew来管理后台服务
在linux下我们经常通过 service 或者 /etc/init.d/来管理我们的后台服务软件,并使用包管理器安装这些软件. 在mac下有homebrew这个好用的工具来安装软件,但是一直没有找到 ...
- Python脚本控制的WebDriver 常用操作 <十四> 处理button dropdown 的定位
测试用例场景 模拟选择下拉菜单中数据的操作 Python脚本 测试用HTML代码: <html> <body> <form> <select name=&qu ...
- linux 文件属性
关于属性的结构 在linux下文件和文件夹都被认为是文件, 所以以下的这个属性对文件和文件夹通用 获取属性的函数有stat/fstat/lstat/fstat struct stat{ mode_t ...
- [SQL_Server_Question]Msg 1105无法为数据库 'tempdb' 中的对象分配空间,因为 'PRIMARY' 文件组已满
错误消息: Msg 1105, Level 17, State 2, Line 266Could not allocate space for object 'dbo.Large Object Sto ...
- iOS应用的真机调试
必须条件:99美元的帐号,没有这个就不用再往下看了. 首先,登录到http://developer.apple.com/devcenter/ios/index.action,如果已经购买了iPhone ...
- win下php5.5.12装不上memcache扩展
WAMP这个集成环境里,php目录下有个php.ini,apache/bin下也有一个php.ini,环境使用的是apache下的,改apache
- ThinkPHP学习笔记 实例化模型的四种方法
创建Action类 [php] <?php class NewObjectAction extends Action{ public function index(){ ...
- skrollr 中文教程
skrollr 0.6.29 skrollr是一个单独的视差滚动的JavaScript库,移动端(Android,iOS,等)和pc都可以使用,压缩后大小仅仅不到12K 使用方法 首先你需要引入skr ...