题目链接:

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. [LOJ2553]暴力写挂

    锟题x2 以下用$a\rightarrow b$表示端点为$a,b$的链 把式子写成$(h_1(x)+h_1(y)-h_1(lca))-h_2(lca')$,第一部分就是$x\rightarrow r ...

  2. [NOIp2016提高组]换教室

    题目大意: 有n节课,第i节课在c[i]上课,同时d[i]也有一节课d[i]. 你有权利向教务处发出m次申请把自己的教室改到d[i],相应的批准概率是k[i]. 教室是图上的一些点,其中每条边都有边权 ...

  3. [转] FileSystemXmlApplicationContext、ClassPathXmlApplicationContext和XmlWebApplicationContext简介

    今天在用Spring时遇到一个问题,提示找不到applicationContext.xml文件.原来是在加载这个文件时调用的方法不太合适,所以造成了程序找不到项目下的xml配置文件. 我们常用的加载c ...

  4. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

  5. JNI小试牛刀

    JNI: JNI是Java Native Interface的缩写,它提供了若干的API实现了Java和其他语言的通信(主要是C&C++).从Java1.1开始,JNI标准成为java平台的一 ...

  6. GridControl事件

    private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventA ...

  7. jQuery匹配各种条件的选择器用法

    :hidden匹配所有的不可见元素,input 元素的 type 属性为 "hidden" 的话也会被匹配到Matches all elements that are hidden ...

  8. xss payload

    xss payload可以使用富客户端文本书写,大多数用javascript,少部分用actionscript等等. 1.盗取cookie,发起cookie劫持 使用xss漏洞插入cookie.js ...

  9. Win8安装程序出现2502、2503错误解决方法

    我是在安装VMware virtualbox的时候遇到的这个问题,上网百度了一下发现这是个在win8系统上安装程序时才会遇到的. 究其原因这个问题还是由于权限问题导致的,解决方法如下: 1,ctrl+ ...

  10. mysql安装以后无法登陆的的解决方法((ERROR 1698 (28000): Access denied for user 'root'@'localhost'))

    mysql安装以后无法登陆的的解决方法((ERROR 1698 (28000): Access denied for user 'root'@'localhost')) 解决步骤: [====> ...