2122. 幸运票

(File IO): input:tickets.in output:tickets.out

时间限制: 1000 ms  空间限制: 262144 KB  具体限制

Goto ProblemSet

题目描述

给你一个数N(1<=N<=50),每张票有2N位,同时给你这2N位上的和S,如果这张票的前N位的和等于后N位的和,那我们称这张票是吉祥的,每一位可以取0-9。

你的任务是计算吉祥票的总数。

输入

输入N和S,S是所以位上的和,假设S<=1000

输出

输出吉祥票的总数

样例输入

2 2

样例输出

4

数据范围限制

见题目描述

Solution

此题很不友好……emmm……

Algorithm1

死命dfs

Code1

 #pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define IL inline
using namespace std; unsigned long long n,s,ans,sum;
IL void dfs(unsigned long long depth,unsigned long long now,unsigned long long sum)
{
if(sum*>s) return;
if(depth==n){
if(sum==s/)
ans++;
return;
}
for(int i=;i<;i++)
{
dfs(depth+,now*+i,sum+i);
}
}
int main()
{
// freopen("tickets.in","r",stdin);
// freopen("tickets.out","w",stdout);
cin>>n>>s;
dfs(,,);
cout<<ans*ans;
return ;
}

Code1

Algorithm2

打了一番表,发现真相……

一个斜着的杨辉三角形*2???

由于某些原因(换了电脑且插不了U盘)

没法详细的讲规律

这是ans,不是ans的平方!

0 0 0 0 0 0 0 0……
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 0 0 ……
1 1 3 3 6 6 10 10 15 15 21 21 28 28 36 36 45 45 55 55 63 63 ……0 0 0 0 ……
1 1 4 4 10   10   20   20 ……

可以用s/2向下取整+1先把重复的删除(calc(n,s/2+1))

然后这个矩阵就有有个规律了:

如果s/2+1小于11的话,memory[i][j]=memory[x-1][y]+memory[x][y-1]

否则memory[i][j]=memory[x-1][y]+memory[x][y-1]-1

#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define IL inline
using namespace std; unsigned long long n,s,ans,sum;
bool vis[][];
unsigned long long memory[][]={
{},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{}
};
IL unsigned long long calc(int x,int y)
{
if(x==||x==)
{
if(y<=)
return ;
else
return ;
}
if(y==) return ;
if(vis[x][y]||memory[x][y]) return memory[x][y];
memory[x-][y]=calc(x-,y);
memory[x][y-]=calc(x,y-);
vis[x-][y]=vis[x][y-]=;
return memory[x][y]=memory[x-][y]+memory[x][y-]-(int)(y>=);
}
IL int read()
{
char ch;int x=;
ch=getchar();
while(ch<''||ch>'') ch=getchar();
while(ch>=''&&ch<='') x=(x<<)+(x<<)+(ch^),ch=getchar();
return x;
}
int main()
{
// freopen("tickets.in","r",stdin);
// freopen("tickets.out","w",stdout);
n=read();
s=read();
ans=calc(n,s/+);
cout<<ans*ans;
return ;
}

但是对拍之后,发现ans*ans很容易会超过unsigned long long!

高精度!

只要加上高精加法和高精乘法就好

纪中20日c组T2 2122. 【2016-12-31普及组模拟】幸运票的更多相关文章

  1. 纪中20日c组模拟赛

    赛后感想 多写点东西总是好的,但是在最后,算法就不要改动了(就这样我少了10分) 题解 T1 2121. 简单游戏 T2 2122. 幸运票

  2. 纪中20日c组模拟赛T1 2121. 简单游戏

    T1 2121. 简单游戏 (File IO): input:easy.in output:easy.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制 Goto Pro ...

  3. 纪中21日T3 2118. 【2016-12-30普及组模拟】最大公约数

    纪中21日T3 2118. 最大公约数 (File IO): input:gcd.in output:gcd.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制 Goto ...

  4. 纪中17日T1 2321. 方程

    纪中17日T1 2321. 方程 (File IO): input:cti.in output:cti.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto ...

  5. 纪中10日T1 2313. 动态仙人掌

    纪中10日 2313. 动态仙人掌 (File IO): input:dinosaur.in output:dinosaur.out 时间限制: 1500 ms  空间限制: 524288 KB  具 ...

  6. 纪中23日c组T2 2159. 【2017.7.11普及】max 洛谷P1249 最大乘积

    纪中2159. max 洛谷P1249 最大乘积 说明:这两题基本完全相同,故放在一起写题解 纪中2159. max (File IO): input:max.in output:max.out 时间 ...

  7. 纪中23日c组T3 2161. 【2017.7.11普及】围攻 斐波那契数列

    2161. 围攻 (File IO): input:siege.in output:siege.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto Prob ...

  8. 洛谷P1880 [NOI1995]石子合并 纪中21日c组T4 2119. 【2016-12-30普及组模拟】环状石子归并

    洛谷P1880 石子合并 纪中2119. 环状石子归并 洛谷传送门 题目描述1 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石 ...

  9. 纪中10日T1 2300. 【noip普及组第一题】模板题

    2300. [noip普及组第一题]模板题 (File IO): input:template.in output:template.out 时间限制: 1000 ms  空间限制: 262144 K ...

随机推荐

  1. .Net Core初识以及启动配置

    .net程序员为什么要学习.net core .Net Core 是.Net的未来,微软在19年 5月已经明确说明,未来只有.Net 5(=.NET Core vNext),.Net 5是.net c ...

  2. Arduino系列之按键模块(一)

    今天我将简单介绍按键模块计数的原理: 我们常用的按键及按键模块有2脚和4脚的,其内部结构如图所示,当按下按键时就会接通按键两端,当放开时,两端自然断开.                         ...

  3. tmobst3an

    1.(单选题)如果数据库是oracle,则generator属性值不可以使用(). A)native B)identity C)hilo D)sequence 解析:identity:生成long, ...

  4. 检测并移除WMI持久化后门

      WMI型后门只能由具有管理员权限的用户运行.WMI后门通常使用powershell编写的,可以直接从新的WMI属性中读取和执行后门代码,给代码加密.通过这种方式攻击者会在系统中安装一个持久性的后门 ...

  5. Linux 系统监控工具 atop

    系统监控是运维工作中重要的一环,本文以 atop 工具为例来介绍系统的重要监控项. atop可以使用yum或apt包管理器进行安装.atop man page 中详细说明了 atop 中各监控项含义及 ...

  6. Trie(字典树)的侃侃

    Trie是什么 ? 字典树 : 见名知意(在树上进行查询). 跟字典相关的必定与查询有密切的关系, 查询就需要一定的媒介作为支撑,树就为这种查询提供支撑. Trie做什么 ? 实现字符串快速检索的多叉 ...

  7. Jmeter之将测试结果导出到Excel

    一:环境准备 1.下载jxl.jar这个jar包 2.下载好之后,放到Jmeter的安装路径下的lib目录下 3.jxl.jar的作用:完成对Excel的读写以及修改操作 如何利用jmter操作exc ...

  8. php面试笔记(2)-php基础知识-常量和数据类型

    本文是根据慕课网Jason老师的课程进行的PHP面试知识点总结和升华,如有侵权请联系我进行删除,email:guoyugygy@163.com 面试是每一个PHP初学者到PHP程序员必不可少的一步,冷 ...

  9. 数据算法 --hadoop/spark数据处理技巧 --(1.二次排序问题 2. TopN问题)

    一.二次排序问题. MR/hadoop两种方案: 1.让reducer读取和缓存给个定键的所有值(例如,缓存到一个数组数据结构中,)然后对这些值完成一个reducer中排序.这种方法不具有可伸缩性,因 ...

  10. LVS 介绍 原理

    一. LVS简介       LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起的自由软件项目,它的官方站点是www.linuxvirtual ...