poj 3844 Divisible Subsequences 剩余类,组合计数
来源:互联网 发布:centos和ubuntu的命令 编辑:程序博客网 时间:2024/05/17 09:05
题目地址: http://poj.org/problem?id=3844
思路: a[i]+a[i+1]+...+a[j]=s[j]-s[i]; 于是整除等价于 s[i]===s[j] (mod d); 然后统计出现了多少次 c[n][2]就可以了 。 值得注意的是,有可能50000* (50000-1)/2 要用long long
每次进入一个新case 后把p 清零,sum【i】表示前i个数的和, 0=<i<=n
代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int sum[50005];int p[1000000];int main(){int T;cin>>T;int d;int n;while(T--){ cin>>d>>n; int temp; memset(p,0,sizeof(p)); for(int i=0;i<n;i++) { scanf("%d",&temp); sum[i+1]=(sum[i]+temp)%d; p[sum[i+1]]++; } p[0]++; long long ans=0; for(int i=0;i<d;i++) { long long temp=p[i]; if(temp>=2) ans+=temp*(temp-1)/2; } cout<<ans<<endl;}}
- poj 3844 Divisible Subsequences 剩余类,组合计数
- poj 3844 Divisible Subsequences 组合数学
- POJ 3844 Divisible Subsequences
- poj 3844 Divisible Subsequences
- POJ 3844Divisible Subsequences
- POJ 3844 Divisible Subsequences
- poj 3844 Divisible Subsequences(数学+抽屉原理)
- POJ 3252 组合计数
- POJ 1019 组合计数
- poj 3734 Blocks 组合计数
- POJ 3761 (组合计数)
- poj 1850 Code(组合计数)
- POJ 1496 POJ 1850 组合计数
- POJ 3252 Round Numbers(组合计数)
- poj 3604 Professor Ben 组合计数
- poj 1496 Word Index 计数/组合数学
- poj 1745 divisible
- Poj 1496 Word Index & Poj 1850 Code (计数 组合数)
- Unity中的事件系统历史
- 随机网络的扩张
- IOS 如何选择delegate、notification、KVO?
- Programming Projects3.4
- Cocos2d-x学习(二十四):vs2010使用vld检测内存泄露
- poj 3844 Divisible Subsequences 剩余类,组合计数
- Android中SparseArray一个写的很人性化的地方
- 在ORACLE中实现SELECT TOP N的方法
- Windows 64bit下安装Apache+Python+mod_wsgi+php
- 基于haar特征的Adaboost人脸检测技术
- Screen 对象,获取客户端显示屏幕的信息
- C++中static的用法总结
- Java ArrayList的使用方法
- POCO库 Foundation::Thread模块(二) 主动对象