题目链接:

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的更多相关文章

  1. UVALive - 6529 找规律+dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/47664 Eleven Time Limit: 5000MS 问题描述 In this problem, we ...

  2. UVALive 4987---Evacuation Plan(区间DP)

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  3. uvalive 6938 区间dp

    看到n范围和给的区间看着就像区间dp 然后怎么cmp感觉都没法进行区间合并 n的300误导了下 没有注意离散化之后对时间可以dp 然而这个dp感觉不太经得起证明的样子... dp[i][j] -> ...

  4. 【BZOJ-4380】Myjnie 区间DP

    4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: ...

  5. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  6. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  7. BZOJ1055: [HAOI2008]玩具取名[区间DP]

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Statu ...

  8. poj2955 Brackets (区间dp)

    题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...

  9. HDU5900 QSC and Master(区间DP + 最小费用最大流)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...

随机推荐

  1. <四边形不等式优化>[NOI1995]石子合并

    留个坑 挺套路的 明天来写个总结 #include<cstdio> #include<algorithm> inline int read() { int x = 0,f = ...

  2. 【高斯消元】CDOJ1783 曜酱的线性代数课堂(一)

    高斯消元求逆矩阵板子. #include<cstdio> #include<cmath> #include<algorithm> #include<cstri ...

  3. 【模拟退火】poj2069 Super Star

    题意:让你求空间内n个点的最小覆盖球. 模拟退火随机走的时候主要有这几种走法:①随机旋转角度. ②直接不随机,往最远的点的方向走,仅仅在尝试接受解的时候用概率.(最小圆/球覆盖时常用) ③往所有点的方 ...

  4. [AGC025D]Choosing Points

    [AGC025D]Choosing Points 题目大意: 输⼊\(n(n\le300),d_1,d_2\),你要找到\(n^2\)个整点\((x,y)\)满⾜\(0\le x,y<2n\). ...

  5. 你真的完全了解Java动态代理吗?看这篇就够了

    之前讲了<零基础带你看Spring源码--IOC控制反转>,本来打算下一篇讲讲Srping的AOP的,但是其中会涉及到Java的动态代理,所以先单独一篇来了解下Java的动态代理到底是什么 ...

  6. Problem E: 零起点学算法34——3n+1问题

    #include<stdio.h> #include<math.h> int main() { int n; n<=pow(,); ; scanf("%d&qu ...

  7. Linux虚拟化技术KVM、QEMU与libvirt的关系(转)

    说明:个人理解,KVM是内核虚拟化技术,而内核是不能使用在界面上使用的,那么此时QEMU提供了用户级别的使用界面,相互辅助.当然,单独使用QEMU也是可以实现一整套虚拟机,不过QEMU+KVM基本是标 ...

  8. 各种GCC

    Cross GCC Cygwin GCC Linux GCC MacOSX GCC MinGW GCC Solaris GCC Clang

  9. JavaScript基础入门教程(一)

    本系列教程的说明 本教程说白了可以说是我自己学习JavaScript的笔记,主要内容参考自<JavaScript权威指南>,部分内容可能来自互联网,本系列教程假设学者之前学过c或者其它的编 ...

  10. Ceph源码解析:CRUSH算法

    1.简介 随着大规模分布式存储系统(PB级的数据和成百上千台存储设备)的出现.这些系统必须平衡的分布数据和负载(提高资源利用率),最大化系统的性能,并要处理系统的扩展和硬件失效.ceph设计了CRUS ...