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: ...
 
随机推荐
- 浏览器的get请求和post请求的区别
			
GET 请求和 POST 请求: 1). 使用GET方式传递参数: ①. 在浏览器地址栏中输入某个URL地址或单击网页上的一个超链接时,浏览器发出的HTTP请求消息的请求方式为 ...
 - PostgreSQL查询长连接
			
apple=# select pid, backend_start, xact_start, query_start, waiting, state, backend_xid from pg_stat ...
 - 转:application/json 四种常见的 POST 提交数据方式
			
四种常见的 POST 提交数据方式 HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 PO ...
 - 實驗項目wordcount
			
wordcount 1.设计思路 第一步 :主函数参数使用命令行参数,定义一个文件指针fp. 第二步:判断能否用只读的形式打开命令行指针中的文件,并让指针指向打开函数,若不能则输出不能读取文件,否则下 ...
 - CF1082E:E.increasing Frequency(贪心&最大连续和)
			
You are given array a a of length n n . You can choose one segment [l,r] [l,r] (1≤l≤r≤n 1≤l≤r≤n ) an ...
 - Spring学习-学习路线
			
Spring的IOC Spring的AOP , AspectJ Spring的事务管理 , 三大框架的整合
 - python 之 collections
			
Python作为一个“内置电池”的编程语言,标准库里面拥有非常多好用的模块.比如今天想给大家 介绍的 collections 就是一个非常好的例子. 基本介绍 我们都知道,Python拥有一些内置的数 ...
 - python学习(二)—简明python教程
			
2016-04-14 20:55:16 八.模块 简介 前面介绍了如何在程序中定义一次函数而重用代码.在其他程序中重用很多函数,就需要使用模块.模块基本上就是一个包含了所有你定义的函数和变量的文件.模 ...
 - 机器学习The Learning Problem——coursera简要总结
			
1.人类及动物的学习模式:观察->学习->技能 机器学习的模式:data->ML(机器学习)->skill 2.那什么是skill:技能是某种表现方法的增进 eg:stac ...
 - codis须知
			
codis是豌豆荚team出的一个redis集群,和官方的集群区别的地方在于 基于proxy,官方是基于gossip codis所有的读写都通过proxy,对于前端业务是透明的 官方的是读写发现在某个 ...