CodeForces 383D Antimatter
线性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的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- iphone下元素放在了一个position: fixed的div中无法点击
网上的说法是这样的: iphone的浏览器有这么一个bug, 当你使用锚定或滚动页面后, 你会发现某些东西不能点击了! 如果你的这个“东西”放在了一个position: fixed的div中, 那么你 ...
- CentOS 7 多网卡绑定
根据官方文档Red_Hat_Enterprise_Linux-7-Networking_Guide-en-US用nmcli做起来还是相当容易的.下面把俺的步骤贴下. 1.查看目前网卡的名称和状态.#n ...
- hudson
来源: hudson入门与实战 http://www.360doc.com/content/15/0304/22/12144668_452603921.shtml Hudson安装配置.部署应用及分析 ...
- Linux openvswitch性能调优
Increasing the flow-eviction threshold The threshold is a type of limit on the number of flows that ...
- java启动子进程以及进程通信
1.利用进程的管道通信传输流 2.子进程没有控制台,正常测试的时候也是没办法看到子进程的输出的,需要传到主线程 3.测试主进程传参给子进程再传回来 4.父进程启动子进程只要执行runtime.exec ...
- html5--基础笔记
1.对于<a>标签 以前: <h2><a href="index.html">The home page</a></h2> ...
- 发现一个c++ vector sort的bug
在开发中遇到一个非常诡异的问题:我用vector存储了一组数据,然后调用sort方法,利用自定义的排序函数进行排序,但是一直都会段错误,在排序函数中打印参加排序的值,发现有空值,而且每次都跟同一个数据 ...
- POJ 2246 Matrix Chain Multiplication
用栈来处理一下就好了. #include<iostream> #include<algorithm> #include<cstdio> #include<cs ...
- hdu_1072_Nightmare(BFS)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1072 题意:给你一个地图,让你在炸弹爆之前找到出口,最初炸弹设定为6,每走一格需要1,中途有地方能让炸 ...
- LeetCode OJ 189. Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...