DP+高精度 URAL 1036 Lucky Tickets
/*
题意:转换就是求n位数字,总和为s/2的方案数
DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k];
高精度直接拿JayYe的:)
异或运算的规则:
0⊕0=0,0⊕1=1
1⊕0=1,1⊕1=0
口诀:相同取0,相异取1
*/
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std; const int numlen = ;
const int numbit = ;
const int addbit = ;
const int maxn = numlen/numbit + ; struct bign {
int len, s[numlen];
bign() {
memset(s, , sizeof(s));
len = ;
}
bign(int num) { *this = num; }
bign(const char *num) { *this = num; }
bign operator = (const int num) {
char s[numlen];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char *num){
int clen = strlen(num);
while(clen > && num[] == '') num++, clen--;
len = ;
for(int i = clen-;i >= ; i -= numbit) {
int top = min(numbit, i+), mul = ;
s[len] = ;
for(int j = ;j < top; j++) {
s[len] += (num[i-j]-'')*mul;
mul *= ;
}
len++;
}
deal();
return *this;
}
void deal() {
while(len > && !s[len-]) len--;
}
bign operator + (const bign &a) const {
bign ret;
ret.len = ;
int top = max(len, a.len), add = ;
for(int i = ;add || i < top; i++) {
int now = add;
if(i < len) now += s[i];
if(i < a.len) now += a.s[i];
ret.s[ret.len++] = now%addbit;
add = now/addbit;
}
return ret;
}
bign operator * (const bign &a)const {
bign ret;
ret.len = len + a.len;
for(int i = ;i < len; i++) {
int pre = ;
for(int j = ;j < a.len; j++) {
int now = s[i]*a.s[j] + pre;
pre = ;
ret.s[i+j] += now;
if(ret.s[i+j] >= addbit) {
pre = ret.s[i+j]/addbit;
ret.s[i+j] -= pre*addbit;
}
}
if(pre) ret.s[i+a.len] = pre;
}
ret.deal();
return ret;
}
}dp[][];
istream& operator >> (istream &in, bign &x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream &out, const bign &x) {
printf("%d", x.s[x.len-]);
for(int i = x.len-;i >= ; i--) printf("%04d", x.s[i]);
return out;
} int main(void) //URAL 1036 Lucky Tickets
{
//freopen ("W.in", "r", stdin); int n, s;
while (scanf ("%d%d", &n, &s) == )
{
if (s & ) {puts (""); continue;} dp[][] = ;
int cur = ;
for (int i=; i<=n; ++i)
{
for (int j=; j<=s/; ++j) dp[cur^][j] = ;
for (int j=; j<=; ++j)
{
for (int k=; k+j<=s/; ++k)
dp[cur^][k+j] = dp[cur^][k+j] + dp[cur][k];
}
cur ^= ;
} cout << dp[cur][s/] * dp[cur][s/] << endl;
} return ;
}
DP+高精度 URAL 1036 Lucky Tickets的更多相关文章
- Ural 1036 Lucky Tickets
Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...
- URAL 1036(dp+高精度)
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- POJ-2346 Lucky tickets(线性DP)
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...
- Codeforces Gym 100418J Lucky tickets 数位DP
Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- 递推DP URAL 1031 Railway Tickets
题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...
- ural 1217. Unlucky Tickets
1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...
- POJ 2346:Lucky tickets
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3247 Accepted: 2136 Des ...
- 1166 矩阵取数游戏[区间dp+高精度]
1166 矩阵取数游戏 2007年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description [ ...
- bzoj 1089 [SCOI2003]严格n元树(DP+高精度)
1089: [SCOI2003]严格n元树 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1250 Solved: 621[Submit][Statu ...
随机推荐
- AptitudeSystem 2.0
AptitudeSystem 2.0(2017-03-07) 描写叙述:Windows内核研究辅助工具 支持的系统:Windows 7.Windows 8.Windows 8.1.Windows 10 ...
- sbt is a build tool for Scala, Java, and more
http://www.scala-sbt.org/0.13/docs/index.html sbt is a build tool for Scala, Java, and more. It requ ...
- Hibernate的一些使用技巧
1.Hibernate是如今最流行的开源对象关系映射(ORM)持久化框架,SSH框架组合是很多JavaEE工程的首选,java持久化框架(JPA)的设计师是Hibernate的作者,因此对于Hiber ...
- node-orm2
最近应老大要求,对orm2进行再一步封装,所以记录下封装和使用心得(文中数据库:mysql). 数据库连接 var orm = require("orm"); orm.connec ...
- Android 返回键的处理
多网友不明确怎样在Android平台上捕获Back键的事件.Back键是手机上的后退键,一般的软件不捕获相关信息可能导致你的程序被切换到后台.而回到桌面的尴尬情况,在Android上有两种方法来获取该 ...
- 【Selenium】Action.moveToElement
使用moveToElement可是实现定位焦点,尝试后测试通过,代码如下 //鼠标单击前商品信息被隐藏,我们需要手动除展示商品标签的隐藏属性 JavascriptExecutor ...
- trying to draw too large(106,975,232 bytes) bitmap.
Loading Large Bitmaps Efficiently This lesson teaches you to Read Bitmap Dimensions and Type Load a ...
- BZOJ_1295_[SCOI2009]最长距离_dij
BZOJ_1295_[SCOI2009]最长距离_dij Description windy有一块矩形土地,被分为 N*M 块 1*1 的小格子. 有的格子含有障碍物. 如果从格子A可以走到格子B,那 ...
- Android适合组件化开发的路由框架:Launch
1.概述 最近越来越不想写代码了,特别是一些重复性的代码,比如由于每次启动一个 Activity,我们都会很习惯的在 Activity 中写下: public static void launch(A ...
- bzoj1925
dp 搬题解~~:http://blog.csdn.net/aarongzk/article/details/44871391 #include<cstdio> using namespa ...