hdu4669Mutiples on a circle
http://acm.hdu.edu.cn/showproblem.php?pid=4669
这题各种错误都来了一遍 预处理一下第一个数作为尾数与相邻前面的数组成的数的余数 然后再与后面的结合求余数
9 6 4 2 8
因为是个环 可以 9 6 4 2 8 9 6 4 2 8 组合 不过 又不能超N
所以先预处理 89 289 4289 64289 的余数 再与后面的组合 删除重复的
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 50005
#define LL __int64
int dp[N][];
int b[N],di[N],pp[N*];
int digit(int x)
{
int i=;
while(x)
{
i++;
x/=;
}
return i;
}
int main()
{
int i,k,n,r,j;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i = ; i <= n ;i++)
for(j = ; j < k ; j++)
dp[i][j] = ;
for(i = ; i <= n ; i++)
{
scanf("%d",&b[i]);
di[i] = digit(b[i]);
}
pp[] = ;
for(i = ; i <= n* ; i++)
pp[i] = (pp[i-]*)%k;
int pre = ;
b[n+] = b[];
di[n+] = di[];
r = ;
for(i = n+ ; i > ; i--)
{
r = (b[i]*pp[pre]+r)%k;
pre+=di[i];
dp[][r]++;
}
int rr = r;
for(i = ; i <= n ; i++)
{
for(r = ; r < k ; r++)
{
int o = (r*pp[di[i]]+b[i])%k;
dp[i][o] += dp[i-][r];
}
rr = (rr*pp[di[i]]+b[i])%k;
dp[i][rr]--;
dp[i][b[i]%k]++;
rr = (rr-pp[pre]*b[i]+k)%k;
if(rr<) rr+=k;
}
LL maxz=;
for(i = ; i <= n ; i++)
{
maxz+=dp[i][];
}
printf("%I64d\n",maxz);
}
return ;
}
hdu4669Mutiples on a circle的更多相关文章
- [翻译svg教程]svg中的circle元素
svg中的<circle> 元素,是用来绘制圆形的,例如 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink= ...
- 设计一个程序,程序中有三个类,Triangle,Lader,Circle。
//此程序写出三个类,triangle,lader,circle:其中triangle类具有类型为double的a,b,c边以及周长,面积属性, //具有周长,面积以及修改三边的功能,还有判断能否构成 ...
- c++作业:Circle
Circle Github链接
- Modified Least Square Method and Ransan Method to Fit Circle from Data
In OpenCv, it only provide the function fitEllipse to fit Ellipse, but doesn't provide function to f ...
- [javascript svg fill stroke stroke-width circle 属性讲解] svg fill stroke stroke-width circle 属性 绘制圆形及引入方式讲解
<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...
- (1)编写一个接口ShapePara,要求: 接口中的方法: int getArea():获得图形的面积。int getCircumference():获得图形的周长 (2)编写一个圆类Circle,要求:圆类Circle实现接口ShapePara。 该类包含有成员变量: radius:public 修饰的double类型radius,表示圆的半径。 x:private修饰的double型变量x,
package com.hanqi.test; //创建接口 public interface ShapePara { //获取面积的方法 double getArea(); //获取周长的方法 do ...
- 东大oj-1591 Circle of friends
题目描述 Nowadays, "Circle of Friends" is a very popular social networking platform in WeChat. ...
- svg学习(四)circle
<circle> 标签 < <?xml version="1.0" standalone="no"?> <!DOCTYPE ...
- 后缀数组 --- WOj 1564 Problem 1564 - A - Circle
Problem 1564 - A - Circle Problem's Link: http://acm.whu.edu.cn/land/problem/detail?problem_id=156 ...
随机推荐
- Java实战之02Hibernate-08二级缓存
十四.Hibernate的二级缓存 1.Hibernate的缓存结构 2.由于二级缓存被多线程共享,就必须有一定的事务访问策略 非严格读写:READ UNCOMMITTED 读写型:READ COMM ...
- VIM 同义词
vim-online-thesaurus A Vim plugin for looking up words in an online thesaurus, Now thesaurus.com 一.原 ...
- strcpy函数导致release版程序崩溃
最近在写一个读取模型文件的小程序.很随意的使用了strcpy函数进行char字符数组的拷贝,这个数组是需要传递给PostMessage作为WPARAM的参数.代码部分如下: char pStrCurr ...
- linux下搭建nginx+php(FastCGI)+mysql运行环境
一.安装环境 1.CentOS5.5 2.php5.4 3.MySQL5.5.19 二.安装程序依赖库和开发环境 为了省事把所需要的库文件全都安装上,可以使用rpm包安装,也可以用yum命令安装, 1 ...
- Poj 1013 Counterfeit Dollar / OpenJudge 1013(2692) 假币问题
1.链接地址: http://poj.org/problem?id=1013 http://bailian.openjudge.cn/practice/2692 http://bailian.open ...
- leetcode Permutations II 无重全排列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...
- 解决MySQL查询不区分大小写
需要设置collate(校对) . collate规则: *_bin: 表示的是binary case sensitive collation,也就是说是区分大小写的 *_cs: case sensi ...
- Project not selected to build for this solution configuration.
Project not selected to build for this solution configuration. When you upgrade your older solutio ...
- 聊天工具实现winform端实现
最近在找能够实现客户端点对点聊天的技术,通过github我发现了一个项目,它能够支持webscoket通讯,服务端是由c#socket完成. 我要的是winform端的通信,所以在他的基础上,增加了桌 ...
- 【BZOJ】1012: [JSOI2008]最大数maxnumber 树状数组求区间最值
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1012 题意:维护一个数列,开始时没有数值,之后会有两种操作, Q L :查询数列末 ...