UVALive 6529 Eleven 区间dp
题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=4540">点击打开链接
题意:
给定一个数,又一次排列这个数的各个位置使得
1、无前导0
2、能被11整除
问:
有多少种组合方法
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 1000000000 + 7;
const int N = 100+2;
const int L = 50+2;
const int M = L*9; char s[N];
int x, sum, len, app[10];
int C[N][N], d[10][L][M], g[N][N], tot[12]; int c(int x, int y) {
if (~C[x][y])
return C[x][y];
if (x == 1 || y==0)
return C[x][y] = 1;
C[x][y] = 0;
for (int i = 0; i <= y; ++i)
C[x][y] = (C[x][y] + c(x-1, y-i))%mod;
return C[x][y];
}
void work() {
int v;
len = strlen(s);
sum = 0;
memset(app, 0, sizeof app);
for (int i = 0; i < len; ++i) {
++ app[s[i]-'0'];
sum += s[i]-'0';
}
tot[0] = 0;
for (int i = 1; i <= 9; ++i)
tot[i] = tot[i-1] + app[i];
x = (len+1)/2;
memset(d, 0, sizeof d);
d[0][0][0] = 1;
for (int i = 0; i <= 8; ++i)
for (int j = 0; j <= x && j <= tot[i]; ++j)
for (int s = 0; s <= j*9; ++s)
if (d[i][j][s] > 0)
for (int k = 0; k <= app[i+1] && k+j <= x; ++k) {
v = (ll)d[i][j][s] * c(j+1,k) % mod;
v = (ll)v*g[len-x-tot[i]+j][app[i+1]-k]%mod;
d[i+1][j+k][s+k*(i+1)] = (d[i+1][j+k][s+k*(i+1)] + v)%mod;
}
int ans = 0;
for (int j = 1; j <= x; ++j)
for (int s = 0; s <= j*9; ++s)
if (d[9][j][s] > 0 && abs(sum-s-s) % 11 == 0) {
int k = x - j;
if (k > app[0])
continue;
ans += (ll)d[9][j][s] * c(j,k) % mod;
ans %= mod;
}
printf("%d\n", ans);
}
int main() {
memset(C, -1, sizeof C);
memset(g, 0, sizeof g);
for (int i = 0; i < N; ++i) {
g[i][0] = g[i][i] = 1;
for (int j = 1 ; j < i; ++j)
g[i][j] = (g[i-1][j] + g[i-1][j-1])%mod;
}
while (~scanf("%s", s))
work();
return 0;
}
UVALive 6529 Eleven 区间dp的更多相关文章
- UVALive - 6529 找规律+dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/47664 Eleven Time Limit: 5000MS 问题描述 In this problem, we ...
- UVALive 4987---Evacuation Plan(区间DP)
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- uvalive 6938 区间dp
看到n范围和给的区间看着就像区间dp 然后怎么cmp感觉都没法进行区间合并 n的300误导了下 没有注意离散化之后对时间可以dp 然而这个dp感觉不太经得起证明的样子... dp[i][j] -> ...
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
随机推荐
- android viewpager fragment 优化 切换界面 延时加载
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 使用 碎片的 设置用户可见暗示visible hint 这个方法来做到. hint 是 ...
- JZYZOJ1527 [haoi2012]高速公路 线段树 期望
http://172.20.6.3/Problem_Show.asp?id=1527 日常线段树的pushdown写挂,果然每次写都想得不全面,以后要注意啊……求期望部分也不熟练,和平均数搞混也是or ...
- [Codeforces 1053B] Vasya and Good Sequences
Link: Codeforces 1053B 传送门 Solution: 其实就是暴力 观察需要满足的条件: 1.个数和为偶数 2.最大个数不大于其它所有个数的和 如果只有第一个条件记录前缀和的奇偶性 ...
- Maven的内置属性
Maven共有6类属性: ①内置属性(Maven预定义属性,用户可以直接使用) ${basedir}表示项目的根路径,即包含pom.xml文件的目录 ${version}表示项目版本 ${projec ...
- [转]Spring Security 可动态授权RBAC权限模块实践
RBAC:基于角色的访问控制(Role-Based Access Control) 先在web.xml 中配置一个过滤器(必须在Struts的过滤器之前) <filter> <fil ...
- [Java基础] Java对象内存结构
转载地址:http://www.importnew.com/1305.html 原文于2008年11月13日 发表, 2008年12月18日更新:这里还有一篇关于Java的Sizeof运算符的实用库的 ...
- LaTeX之参考文献的写法
在编写latex文件时,参考文献是个比较头疼的问题,以前自己写的时候总是用 \begin{thebibliography}\bibitem author,article, year, vol,\end ...
- ISP图像调试工程师——tone Mapping(ISP)
http://www.cnblogs.com/bigbigtree/p/3458797.html
- HLJU 1221: 高考签到题 (三分求极值)
1221: 高考签到题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 9 Solved: 4 [Submit][id=1221">St ...
- R简易安装
post={"title":"my Blog post","content":"Here's my blog post" ...