Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

You are given a number 1 ≤ N ≤ 50. Every ticket has its 2 N-digit number. We call a ticket lucky, if the sum of its first N digits is equal to the sum of its last N digits. You are also given the sum of ALL digits in the number. Your task is to count an amount of lucky numbers, having the specified sum of ALL digits.

Input

Two space-separated numbers: N and S. Here S is the sum of all digits. Assume that 0 ≤ S ≤ 1000.

Output

The amount of lucky tickets.

Sample Input

input output
2 2
4

Hint

The tickets are 0101, 0110, 1001, 1010 in the example above
求前N位与后N位各个位和相等且总和等于S的2N位数的个数。
注意:每个位上的数字是0-9也就是十进制
状态转移方程:dp[i][j]=sum(dp[i-1][j-k],0<=k<=9)。可想而知最后的数一定会很大。所有操作都用高精度来做
#include<stdio.h>
#include<cstring>
#include<iostream>
using namespace std;
int dp[][][];//第100位存的是数据的长度
int n,tot;
void add(int sum[],int num[])
{
int i,j,temp[];
int len1=sum[],len2=num[];
int max=len1>len2 ? len1:len2;
int jin=;
for(i=;i<max;i++){
int m=jin+sum[i]+num[i];
if(m>=) {jin=;m-=;}
else jin=;
temp[i]=m;
}
if(jin) temp[i++]=jin;
for(j=;j<i;j++)
sum[j]=temp[j];
sum[]=i;
}
void muti_dan(int num[],int data[],int n,int h)
{
int temp[],i,j;
memset(temp,,sizeof(temp));
int len=num[];
int jin=;
for(i=;i<len;i++){
int m=num[i]*n+jin;
jin=m/;
if(jin)m-=jin*;
temp[i]=m;
}
if(jin) temp[i++]=jin;
data[-h]=i;
for(j=;j<i;j++){
data[j]=temp[j];
}
}
void multi(int num[],int num1[])
{
int temp[],sum[],i,j;
memset(sum,,sizeof(sum));
int len1=num[],len2=num1[];
for(j=;j<len2;j++){
memset(temp,,sizeof(temp));
muti_dan(num,&temp[j],num1[j],j);
temp[]+=j;
add(sum,temp);
}
for(i=;i<sum[];i++){
num[i]=sum[i];
}
num[]=sum[];
}
void display(int num[])
{
int len=num[];
for(int i=len-;i>;i--)
cout<<num[i];
cout<<num[]<<endl;
}
void solve()
{
int i,j,k;
if(tot%) {printf("0\n");return;}
int sum=tot/;
memset(dp,,sizeof(dp));
for(i=;i<;i++) {
dp[][i][]=;
dp[][i][]=;
} for(i=;i<n-;i++){
for(j=;j<=sum;j++){
for(k=;k<=&&j+k<=sum;k++){
add(dp[i+][j+k],dp[i][j]);
}
}
} multi(dp[n-][sum],dp[n-][sum]);
display(dp[n-][sum]);
}
int main(void)
{
while(cin>>n>>tot){
solve();
}
return ;
}

URAL 1036(dp+高精度)的更多相关文章

  1. DP+高精度 URAL 1036 Lucky Tickets

    题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...

  2. 1166 矩阵取数游戏[区间dp+高精度]

    1166 矩阵取数游戏 2007年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description [ ...

  3. bzoj 1089 [SCOI2003]严格n元树(DP+高精度)

    1089: [SCOI2003]严格n元树 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1250  Solved: 621[Submit][Statu ...

  4. CF23 E. Tree 树形dp+高精度

    题目链接 CF23 E. Tree 题解 CF竟让卡常QAQ dp+高精度 dp[x][j]表示以x为根的子树,x所属的联通块大小为j,的最大乘积(不带j这块 最后f[x]维护以x为根的子树的最大答案 ...

  5. 【bzoj2764】[JLOI2011]基因补全 dp+高精度

    题目描述 在生物课中我们学过,碱基组成了DNA(脱氧核糖核酸),他们分别可以用大写字母A,C,T,G表示,其中A总与T配对,C总与G配对.两个碱基序列能相互匹配,当且仅当它们等长,并且任意相同位置的碱 ...

  6. poj 1205 :Water Treatment Plants (DP+高精度)

    题意:有n个城市,它们由一个污水处理系统连接着,每个城市可以选择 1.将左边城市过来的污水和右边城市过来的污水连同本身的污水排到河里  >V< 2.将左边来的污水连同自己的污水排到右边   ...

  7. URAL 1012 K-based Numbers. Version 2(DP+高精度)

    题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...

  8. Ural 1036 Lucky Tickets

    Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...

  9. POJ 1625 Censored!(AC自动机+DP+高精度)

    Censored! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6956   Accepted: 1887 Descrip ...

随机推荐

  1. 要不要用STL的问题——真理是越辩越明的~

    QtWidgets的维护者 Marc Mutz 有一篇博客比较详尽的介绍了 Qt自己的容器.介绍了何时用什么比较好https://marcmutz.wordpress.com/effective-qt ...

  2. 剑指offer 25 二叉树中和为某一值的路径

    非递归方法: class Solution { public: vector<vector<int>> FindPath(TreeNode* root,int expectNu ...

  3. UVa 10491 Cows and Cars (概率&广义三门问题 )

    10491 - Cows and Cars Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

  4. 3.一步一步学c#(三):对象和类型

    类和结构 类和结构实际上都是创建对象的模板,每个对象都包含数据,并提供了处理和访问数据的方法,. 结构与类的区别是它们在内存中的存储方式,访问方式(类是存储在堆(heap)上的引用类型),而结构是存储 ...

  5. 自己写的sql server触发器练练--高手请您跳过吧

    set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo ALTER TRIGGER [insertReplyToic] ON [dbo].[bbsReplyTopic] ...

  6. matlab GUI之常用对话框(四)-- 输入对话框 inputdlg、目录对话框 uigetdir、列表对话框 listdlg

    常用对话框(四) 1.输入对话框  inputdlg answer = inputdlg(prompt) answer = inputdlg(prompt,dlg_title) answer = in ...

  7. 查询离指定日期最近的一条数据(oracle)

    select * from ( Select   *   from   t_currency_rate   where f_orig_curr='USD'   and f_dest_curr='RMB ...

  8. Clamp函数

    Clamp函数可以将随机变化的数值限制在一个给定的区间[min, max]内: template<class T> T Clamp(T x, T min, T max) { if (x & ...

  9. Oracle学习之常见问题处理

    转自:http://blog.csdn.net/liusong0605/article/details/16349121 安装完oracle并启动服务后,通过sqlPlus无法登录,出现如下错误: s ...

  10. centos 安装mysql密码修改后还是不能连接的原因

    centos 上安装mysql密码修改后还是不能连接出现错误:ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for ...