srm 555
2015-11-23 16:05
337 查看
欢迎点此阅读QvQ
255
Description
问能将一个0/10/1串最少分成几个串使得每个串都是55的整数次幂,且没有前导零Solution
dp即可,dp[i]dp[i]表示前ii个字符分割的结果,枚举一个分割点jj,checkcheck即可Code
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define F first #define S second typedef long long LL; typedef pair<int, int> pii; const int N = 55; int dp ; struct CuttingBitString { bool ok(LL x) { while (x && x % 5 == 0) x /= 5; return x == 1; } int getmin(string S) { string s = "0" + S + "1"; int n = s.size(); for (int i = 1; i <= n; ++i) dp[i] = 10000; for (int i = 1; i < n; ++i) { if (s[i] == '1') { for (int j = 0; j < i - 1; ++j) { if (dp[j] == 10000 || s[j + 1] == '0') continue; LL now = 0; for (int k = j + 1; k <= i - 1; ++k) now = now * 2 + (s[k] == '1' ? 1 : 0); if (ok(now)) dp[i - 1] = min(dp[i - 1], dp[j] + 1); } } } return dp[n - 2] == 10000 ? -1 : dp[n - 2]; } };
555
Description
有一个H∗WH*W的全00矩阵,给定对行列操作数,每次操作将行列0/10/1翻转,使得最后矩阵11的个数为SS,求方案数两个方案不同当且仅当有一行或列操作数不同
Solution
很容易想到操作两次相当于没操作,枚举行列分别操作11次的个数,剩下的相当于nn个物品(n对操作两次)放到mm个不同盒子的方案数,即(n+m−1n)\binom{n+m-1}{n},统计即可Code
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define F first #define S second typedef long long LL; typedef pair<int, int> pii; const int N = 1600, M = 555555555; int c[N << 1][N << 1]; struct XorBoard { int count(int H, int W, int Rcount, int Ccount, int S) { for (int i = 0; i <= 1555 * 2; ++i) { c[i][0] = 1; for (int j = 1; j <= i; ++j) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M; } int ans = 0; for (int i = 0; i <= Rcount && i <= H; ++i) for (int j = 0; j <= Ccount && j <= W; ++j) { if (i * W + j * H - 2 * i * j != S) continue; if ((Rcount - i) & 1 || (Ccount - j) & 1) continue; int rl = (Rcount - i) / 2, cl = (Ccount - j) / 2; (ans += (LL)c[rl + H - 1][rl] * c[H][i] % M * c[cl + W - 1][cl] % M * c[W][j] % M) %= M; } return ans; } };
相关文章推荐
- Interview Summary
- AlertDialog使用
- tableView的属性设置解析
- java日期格式大全 format SimpleDateFormat
- ServletRequest,HttpServletRequest ServletResponse,ServletResponse的区别
- 被忽略的技能
- 手游性能之渲染分析
- JAVA调用HTTPS双向认证API
- c:out escapeXml
- 第12周项目2-操作用邻接表存储的图
- 做一个Active To
- 本人对Oracle Inventory模块的一些了解
- linux shell编程
- Web Service入门教程
- 编译spark输出的信息
- 学习日记--网络通信框架--Volley应用
- Cookie工具类
- 声波通信开源项SinVoice介绍三
- 委托-异步调用-泛型委托-匿名方法-Lambda表达式-事件
- 问题:Oracle to_date;结果:oracle常用的时间格式转换