Inclusion–exclusion principle(动态规划)
把(2, 3, 5, 7)称为primes,能被primes整除的我们称之为Walprimes,比如
int void F(string s, int prime){
int R[s.length()][prime];
memset(R, , sizeof(R));
for(int i= s.length()-;i>=; i--){
int first = s[i] - '';
for(int k = i+; k < s.length(); j++){ //对R的第一维进行遍历
for(int j = ; j < primes; j ++){ //对R的第二维进行遍历
R[i][j] += R[k][(prime+(j-first)%prime)%prime]; //i+...
R[i][j] += R[k][(prime+(i-first)%prime)%prime]; //i-...
}
first = *first +s[k]; //i后面既没+也没-
}
R[i][first % p] += ; //最后一个first
}
return return R[][];
}
int walprimes(const string& s) {
return F(s, ) + F(s, ) + F(s, ) + F(s, )
- F(s, * ) - F(s, * ) - F(s, * ) - F(s, * ) - F(s, * ) - F(s, * )
+ F(s, * * ) + F(s, * * ) + F(s, * * ) + F(s, * * )
- F(s, * * * );
}
Inclusion–exclusion principle(动态规划)的更多相关文章
- 2016 Multi-University Training Contest 9 solutions BY 金策工业综合大学
A Poor King Tag: Reversed BFS Preprocessing is needed to calculate answers for all positions (states ...
- Robots on a grid(DP+bfs())
链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585 Current Server Time: 2013-08-27 20:42:26 Ro ...
- I am Nexus Master!(虽然只是个模拟题。。。但仍想了很久!)
I am Nexus Master! The 13th Zhejiang University Programming Contest 参见:http://www.bnuoj.com/bnuoj/p ...
- UESTC 1852 Traveling Cellsperson
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 1851 Kings on a Chessboard
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...
- SPOJ 375. Query on a tree (树链剖分)
Query on a tree Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Ori ...
- Cellphone Typing 字典树
Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Ori ...
- The Hundred Greatest Theorems
The Hundred Greatest Theorems The millenium seemed to spur a lot of people to compile "Top 100& ...
- 第12届北师大校赛热身赛第二场 A.不和谐的长难句1
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php? pid=17121 2014-04-25 22:59:49 不和谐的长难句1 Time Limit: ...
随机推荐
- Beta阶段第2周/共2周 Scrum立会报告+燃尽图 09
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2389] 版本控制:https://git.coding.net/liuyy08 ...
- 折叠纸片PFold.js
PFold.js是一款折叠纸片插件,支持定义折叠纸牌数量.折叠动画效果.折叠方向,而且还支持折叠结束后回调方法. 在线实例 效果一 效果二 效果三 使用方法 <div id="uc-c ...
- react拖拽(表格拖拽排序、普通拖拽排序以及树形拖拽排序)
表格拖拽排序:组件地址:https://reactabular.js.org/#/drag-and-drop 拖动的排序是用React-DnD:React-DnD:http://react-dnd.g ...
- Leetcode 1022. Sum of Root To Leaf Binary Numbers
dfs class Solution: def sumRootToLeaf(self, root: TreeNode) -> int: stack=[(root,0)] ans=[] bi_st ...
- Mysql 时间日期函数运用与总结
Mysql 中的时间与日期常常会用到,但是每次都得找,这里结合工作日常总结一下. |--获取当前时间[正常时间] 1. MySQL 获得当前时间函数:current_timestamp, curren ...
- Luogu2435 染色【状压qwq】【轮廓线DP】
LINK 题目大意 有一个 n 行 m 列的格点图,你需要给每个点上染上 k 种颜色中的一种,要求没有两个相邻点颜色相同.给定第一行与最后一行的染色,试求总染色方案数. 思路 暴力预处理状态暴力转移可 ...
- 7-17 Hashing(25 分)
The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...
- 《DSP using MATLAB》Problem 2.19
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- Python 字典(Dictionary) update()方法
refer to: http://www.runoob.com/python/att-dictionary-update.html
- StreamSets 设计Edge pipeline
edge pipeline 运行在edge 执行模式,我们可以使用 data collector UI 进行edge pipeline 设计, 设计完成之后,你可以部署对应的pipeline到edge ...