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, ...
随机推荐
- 如何上传word
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha word图片上传控件 word 图片 上传
- Android Studio检测内存泄露和性能
韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha 313134555@qq.com 首先需要明白一个概念, 内存泄露就是指,本应该回收的内存,还驻留在内存中. 一般情况下,高密度的 ...
- noip 2016 day2 t1组合数问题
题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...
- Codeforces 724E Goods transportation(最小割转DP)
[题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...
- [LOJ2553]暴力写挂
锟题x2 以下用$a\rightarrow b$表示端点为$a,b$的链 把式子写成$(h_1(x)+h_1(y)-h_1(lca))-h_2(lca')$,第一部分就是$x\rightarrow r ...
- 【DFS】Gym - 100781A - Adjoin the Networks
给你一个森林,让你把它连接成一颗树,使得直径最小. 就求出每颗树的重心以后,全都往直径最大的那个的重心上连,一般情况是最大/2+次大/2+1,次大/2+第三大/2+2 中取较大者. 还有些特殊情况要特 ...
- 【可持久化数组】【rope】bzoj3673 bzoj3674 可持久化并查集 by zky
rope教程:http://blog.csdn.net/iamzky/article/details/38348653 Code(bzoj3673): #include<cstdio> # ...
- 原生js实现Ajax请求
总的来说,Ajax是与服务器交换数据并更新部分网页的艺术,在不重新加载整个网页的情况下,异步请求数据并刷新页面.举一个小的例子:Goole搜索页面.当用户在输入框输入关键字的时候,JavaScript ...
- PHP与Web页面的交互
1.form表单默认情况下提交数据的方式为get方式. 2.PHP脚本用来处理表单数据的预定义变量是$_GET,$_POST(区分大小写) 代码示例:(特别注意复选框属性name的时候加数组) sim ...
- [转]java中JSONObject与JSONArray的使用详细说明及有关JSON的工具类
JSONObject与JSONArray的使用 一.JAR包简介 要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: 1.commons-lang.jar 2.c ...