线性DP。

dp[i][j]表示以第i个数字为结尾的,字串和为j的有几种。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const long long mod=1e9+;
const int f=;
const int maxn=+;
int n,a[maxn];
long long dp[maxn][*maxn]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]); memset(dp,,sizeof dp); for(int i=;i<=n;i++)
{
for(int j=-f;j<=f;j++)
{
if(j-a[i]>=-f&&j-a[i]<=f)
dp[i][j+f]=(dp[i][j+f]+dp[i-][j-a[i]+f])%mod;
if(j+a[i]>=-f&&j+a[i]<=f)
dp[i][j+f]=(dp[i][j+f]+dp[i-][j+a[i]+f])%mod;
}
dp[i][a[i]+f]++;
dp[i][-a[i]+f]++;
} long long ans=;
for(int i=;i<=n;i++) ans=(ans+dp[i][f])%mod;
printf("%lld\n",ans); return ;
}

CodeForces 383D Antimatter的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. (转载)CSS中zoom:1的作用

    CSS中zoom:1的作用兼容IE6.IE7.IE8浏览器,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:触发IE浏览器的haslayout解决ie下的浮动,margin重叠等一些问题. ...

  2. submit提交表单后,不刷新当前页面

    <form method="get" target="test" action="a.html"> <input type ...

  3. pumping lemma for finite regular language?

    some books describe pumping lemma as this: Let L be a regular language. Then there exists an integer ...

  4. javaScript中的一些知识

    利用js动态生成table <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http ...

  5. Servlet详解

    原文出处:http://blog.csdn.net/q547550831/article/details/50458456 Servlet详解 基本概述 Session在计算机中,尤其是在网络应用中, ...

  6. java 图片高保真缩放

    public class NarrowImage { /**     * @param im     *            原始图像     * @param resizeTimes     *  ...

  7. check2

    //文件check.js //将方法句柄赋值给变量$,简化document.getElementById(); var $ = document.getElementById; //定义模拟类(定义C ...

  8. JS获取网页中HTML元素的几种方法分析

    getElementById getElementsByName getElementsByTagName 大概介绍 getElementById ,getElementsByName ,getEle ...

  9. LINUX修改IP地址

    以前都是使用自动IP动态分配获取IP的,虽然每次获得的ip都是相同的,但我还是决定自己设置一个IP.输入命令:[root@localhost ~]# ifconfig eth0 219.246.177 ...

  10. STM32F446 OTG_FS_DP/DM调试

    之前项目用STM32F207,现在升级到用STM32F446处理器,用到USB的OTG_FS模式接法: 1.USB只连接了DP/DM 2.DP需上拉1.5K的电阻到3.3V 3.PA9(VBUS) 和 ...