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 ;
}

Ural 1036 Lucky Tickets的更多相关文章

  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. URAL 1036(dp+高精度)

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

  3. ural 1217. Unlucky Tickets

    1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...

  4. POJ-2346 Lucky tickets(线性DP)

    Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...

  5. POJ 2346:Lucky tickets

    Lucky tickets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3247   Accepted: 2136 Des ...

  6. Codeforces Gym 100418J Lucky tickets 数位DP

    Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  7. CF1096. G. Lucky Tickets(快速幂NTT)

    All bus tickets in Berland have their numbers. A number consists of n digits (n is even). Only k dec ...

  8. 递推DP URAL 1031 Railway Tickets

    题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...

  9. URAL 1031. Railway Tickets(spfa)

    题目链接 不知为何会在dp里呢...INF取小了,2Y. #include <cstring> #include <cstdio> #include <string> ...

随机推荐

  1. bzoj 1725: [Usaco2006 Nov]Corn Fields牧场的安排【状压dp】

    压一维状态,转移时把符合条件的上一行加上 #include<iostream> #include<cstdio> using namespace std; const int ...

  2. 源码阅读之LinkedHashMap(JDK8)

    概述 LinkedHashMap继承自HashMap,实现了Map<K,V>接口.其内部还维护了一个双向链表,在每次插入数据,或者访问.修改数据时,会增加节点.或调整链表的节点顺序.以决定 ...

  3. web界面bug-临时

    一.登录页面 二.首页 三.项目 四.项目池 五.专家管理 六.审批 七.日/周报 八.设置

  4. 例题 5-1 STL

    Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on the ...

  5. http2及server push

      本文主要研究下java9+springboot2+undertow2启用http2及server push maven <parent> <groupId>org.spri ...

  6. mongodb的安装以及客户端

    mongodb是一种非关系型的数据库,与传统的sql有很大的不同,但都是用于数据管理的,本人也是初学,很多地方都是模仿,在这里只是记录本人初次安装mongodb和客户端,记录一下安装的步骤,以便以后用 ...

  7. Matlab vs Python 作图

    -- Matlab 作图示例 x=-3:0.00003:3; y1=sin(x)./x; y2=x./sin(x); plot(x,y1,x,y2); -- Python 作图示例 import nu ...

  8. Hadoop Hive概念学习系列之HiveQL编译基础(十)

    由客户端提交的HiveQL语句将最终被转换为一个或多个MapReduce任务并提交由Hadoop执行.不包含聚合和连接的简单SELECT语句可以使用一个单独的只包含Map阶段的任务实现.使用GROUP ...

  9. ES6:Generator函数(1)

    Generator函数是ES6提供的一种异步编程解决方案.它会返回一个遍历器对象 function* helloWorldGenerator(){ yield “hello”; yield “worl ...

  10. 前端--2、CSS基础

    CSS的部分: CSS四种类引入方式(了解) style的定义原则: 基本选择器 示例: 层级选择器 组合选择器 后代选择器 ★ 子代选择器 毗邻选择器 普通兄弟选择器 “与”选择器 ★ “或”选择器 ...