B1072 [SCOI2007]排列perm 状压dp
很简单的状压dp,但是有一个事,就是。。。我数组开大了一点,然后每次memset就会T,然后开小就好了!!!震惊!以后小心点这个问题。
题干:
Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0)。例如123434有90种排列能
被2整除,其中末位为2的有30种,末位为4的有60种。
Input 输入第一行是一个整数T,表示测试数据的个数,以下每行一组s和d,中间用空格隔开。s保证只包含数字0,
, , , , , , , , .
Output
每个数据仅一行,表示能被d整除的排列的个数。
Sample Input Sample Output HINT
在前三个例子中,排列分别有1, , 3628800种,它们都是1的倍数。
【限制】
%的数据满足:s的长度不超过10, <=d<=, <=T<=
Source
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
char s[];
int t;
ll d;
ll dp[ << ][];
ll num[],p[];
int main()
{
read(t);
while(t--)
{
clean(dp);clean(num);clean(p);
scanf("%s",s + );
int l = strlen(s + );
// cout<<l<<endl;
duke(i,,l)
num[s[i] - '']++,p[i] = s[i] - '';
read(d);
dp[][] = ;
duke(i,,( << l) - )
{
duke(j,,d - )
{
duke(k,,l)
{
if((i & ( << (k - ))) == )
{
dp[i | ( << (k - ))][(j * + p[k]) % d] += dp[i][j];
}
}
}
}
// cout<<"QAQ"<<endl;
ll ans = dp[( << l) - ][];
duke(i,,)
{
duke(j,,num[i])
ans /= j;
}
printf("%lld\n",ans);
}
return ;
}
/*
7
000 1
001 1
1234567890 1
123434 2
1234 7
12345 17
12345678 29
*/
B1072 [SCOI2007]排列perm 状压dp的更多相关文章
- [BZOJ1072][SCOI2007]排列perm 状压dp
1072: [SCOI2007]排列perm Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2488 Solved: 1546[Submit][St ...
- BZOJ 1072 [SCOI2007]排列perm ——状压DP
[题目分析] 没什么好说的,水题. 代码比较丑,结果需要开long long 时间爆炸 [代码] #include <cstdio> #include <cstring> #i ...
- bzoj 1072: [SCOI2007]排列perm 状压dp
code: #include <bits/stdc++.h> #define N 1005 using namespace std; void setIO(string s) { stri ...
- 暑假集训Day 4 P4163 [SCOI2007]排列 (状压dp)
状压dp (看到s的长度不超过10就很容易想到是状压dp了 但是这个题的状态转移方程比较特殊) 题目大意 给一个数字串 s 和正整数 d, 统计 s 有多少种不同的排列能被 d 整除(可以有前导 0) ...
- BZOJ 1072: [SCOI2007]排列perm 状态压缩DP
1072: [SCOI2007]排列perm Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能被2整除,其中末位为 ...
- [BZOJ 1072] [SCOI2007] 排列perm 【状压DP】
题目链接:BZOJ 1072 这道题使用 C++ STL 的 next_permutation() 函数直接暴力就可以AC .(使用 Set 判断是否重复) 代码如下: #include <io ...
- BZOJ1072 排列perm 【状压dp】
Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能 被2整除,其中末位为2的有30种,末位为4的有60种. Inpu ...
- 【BZOJ1072】【SCOI2007】排列 [状压DP]
排列 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 给一个数字串s和正整数d, 统计s有多 ...
- 排列perm HYSBZ - 1072(状压dp/暴力)
Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能被2整除,其中末位为2的有30种,末位为4的有60种. Input ...
随机推荐
- Spring Boot 2.0的属性绑定
Spring Boot2.0的属性绑定 原文从Spring boot第一个版本以来,我们可以使用@ConfigurationProperties注解将属性绑定到对象.也可以指定属性的各种不同格式.比如 ...
- 【nginx】解决nginx搭建图片服务器访问图片404
图片通过ftp服务上传到/home/ftpuser/www/images目录下后访问 http://192.168.128.128/images/xxx.jpg 还是 404 NOT FOUND ,解 ...
- Configure a proxy for your API calls with Angular CLI
Table of contents Local development setup with Angular Issue: Dev server plus backend API Configurin ...
- CSDN怎么转载别人的博客
在参考"如何快速转载CSDN中的博客"后,由于自己不懂html以及markdown相关知识,所以花了一些时间来弄明白怎么转载博客,以下为转载CSDN博客步骤和一些知识小笔记. 参考 ...
- C++ Primer(第4版)-学习笔记-第5部分:高级主题
第17章 用于大型程序的工具 异常处理 不存在数组或函数类型的异常.相反,如果抛出一个数组,被抛出的对象转换为指向数组首元素的指针,类似地,如果抛出一个函数,函数被转换为指向该函数的指针. 不要抛出 ...
- Effective C++ 一些记录和思考
Effective C++ Iter 3 - 尽可能使用 const 一个反逻辑的 bitwise const class Text { ... char& operator[](std::s ...
- Python的import module与form module import的区别
import moduleName 如果要使用moduleName模块中的方法时,是moduleName.method(点方法), 比如moduleName中有个方法是set,则使用的是moduleN ...
- 整理推荐比较好用的具有书签搜索功能的chrome插件
平时在整理学习chrome插件的过程中,经常会去试用各种大家推荐的插件.在去年我们的一篇文章:推荐六款好用的书签收藏夹剪藏型管理插件.这里面介绍的是收藏书签的插件.而随着我们使用chrome越来越频繁 ...
- graph.h
#ifndef _GRAPH_#define _GRAPH_#include<stdio.h>#include<stdlib.h>#include<string.h> ...
- 天猫双11红包前端jQuery
[01] 浏览器支持:IE10+和其他现代浏览器. 效果图: 步骤: HTML部分: <div class="opacity" style=&qu ...