Lucky Tickets

Time Limit: 2000ms
Memory Limit: 16384KB

This problem will be judged on Ural. Original ID: 1036
64-bit integer IO format: %lld      Java class name: (Any)

 
You are given a number 1 ≤ N ≤ 50. Every ticket has its 2N-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

2 2

Sample Output

4

Hint

The tickets are 0101, 0110, 1001, 1010 in the example above
 
解题:动态规划$dp[i][j]表示处理到了第i位,且前i位的和为j的方案数$
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MAXN 100
struct HP {
int len,s[MAXN];
HP() {
memset(s,,sizeof(s));
len = ;
}
HP operator=(const char *num) { //字符串赋值
len = strlen(num);
for(int i = ; i < len; i++) s[i] = num[len-i-]-'';
}
HP operator=(int num) { //int 赋值
char s[MAXN];
sprintf(s,"%d",num);
*this = s;
return *this;
}
HP(int num) {
*this = num;
}
HP(const char*num) {
*this = num;
}
string str()const { //转化成string
string res = "";
for(int i = ; i < len; i++) res = (char)(s[i]+'') + res;
if(res == "") res = "";
return res;
}
HP operator +(const HP& b) const {
HP c;
c.len = ;
for(int i = ,g = ; g||i < max(len,b.len); i++) {
int x = g;
if(i < len) x += s[i];
if(i < b.len) x += b.s[i];
c.s[c.len++] = x%;
g = x/;
}
return c;
}
void clean() {
while(len > && !s[len-]) len--;
} HP operator *(const HP& b) {
HP c;
c.len = len + b.len;
for(int i = ; i < len; i++)
for(int j = ; j < b.len; j++)
c.s[i+j] += s[i]*b.s[j];
for(int i = ; i < c.len-; i++) {
c.s[i+] += c.s[i]/;
c.s[i] %= ;
}
c.clean();
return c;
}
HP operator - (const HP& b) {
HP c;
c.len = ;
for(int i = ,g = ; i < len; i++) {
int x = s[i]-g;
if(i < b.len) x -= b.s[i];
if(x >= ) g = ;
else {
g = ;
x += ;
}
c.s[c.len++]=x;
}
c.clean();
return c;
}
HP operator /(const HP &b) {
HP c, f = ;
for(int i = len-; i >= ; i--) {
f = f*;
f.s[] = s[i];
while(f >= b) {
f = f - b;
c.s[i]++;
}
}
c.len = len;
c.clean();
return c;
}
HP operator % (const HP &b) {
HP r = *this / b;
r = *this - r*b;
return r;
}
HP operator /= (const HP &b) {
*this = *this / b;
return *this;
}
HP operator %= (const HP &b) {
*this = *this % b;
return *this;
}
bool operator < (const HP& b) const {
if(len != b.len) return len < b.len;
for(int i = len-; i >= ; i--)
if(s[i] != b.s[i]) return s[i] < b.s[i];
return false;
}
bool operator > (const HP& b) const {
return b < *this;
}
bool operator <= (const HP& b) {
return !(b < *this);
}
bool operator == (const HP& b) {
return !(b < *this) && !(*this < b);
}
bool operator != (const HP &b) {
return !(*this == b);
}
HP operator += (const HP& b) {
*this = *this + b;
return *this;
}
bool operator >= (const HP &b) {
return *this > b || *this == b;
}
};
istream& operator >>(istream &in, HP& x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator <<(ostream &out, const HP& x) {
out << x.str();
return out;
}
HP dp[][];
int main(){
dp[][] = ;
for(int i = ; i < ; ++i)
for(int j = ; j <= i*; ++j)
for(int k = ; k < ; ++k)
dp[i][j + k] = dp[i][j + k] + dp[i-][j];
int n,s;
while(~scanf("%d%d",&n,&s)){
if(s&) puts("");
else cout<<dp[n][s>>]*dp[n][s>>]<<endl;
}
return ;
}

最新文章

  1. lucene全文检索---打酱油的日子
  2. Java 静态语句块、语句块、构造函数执行顺序
  3. LaTex 插入图片
  4. jQuery的 delegate问题
  5. NOI2002 洛谷 P1196 银河英雄传说
  6. C++学习之const整理总结
  7. PHP实现遍历、复制、删除目录
  8. 细说PHP中strlen和mb_strlen的区别
  9. 配置SSH免密码验证
  10. 基于CANVAS与MD5的客户端生成验证码
  11. inline函数和一般的函数有什么不同
  12. getResourceAsStream和getResource的用法
  13. 安装grub
  14. java 中 “文件” 和 “流” 的简单分析
  15. UWP 手绘视频创作工具技术分享系列 - Ink &amp; Surface Dial
  16. qq客服代码实现过程
  17. php 类的相互访问
  18. C# XML序列化/反序列化参考
  19. Android 应用内悬浮控件实践总结
  20. 【原】Java学习笔记015 - 面向对象

热门文章

  1. uml图六种箭头的含义(转载)
  2. bzoj 1232: [Usaco2008Nov]安慰奶牛cheer【最小生成树】
  3. MySQL索引使用以及优化
  4. [Qt Creator 快速入门] 第5章 应用程序主窗口
  5. [转]c++中的string常用函数用法总结
  6. 莫队算法 BOJ 2038 [2009国家集训队]小Z的袜子(hose)
  7. jmeter生成时间的函数
  8. EasyUI系列学习(五)-Resizable(调整大小)
  9. 图标文件ico制作以及使用说明
  10. Java线程及Jvm监控工具