cf 383 D
1 second
256 megabytes
standard input
standard output
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
4
1 1 1 1
12
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
dp 背包问题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAX_N = ;
const int MOD = 1e9 + ;
int N,_max = ;
int a[MAX_N],dp[MAX_N][]; void solve() {
for(int i = ; i <= N; ++i) {
for(int j = * _max; j >= ; --j) {
//dp[i][j] = dp[i - 1][j];
int v = ;
if(j - a[i] == + _max) v = ;
dp[i][j] = (dp[i][j] + v + dp[i - ][j - a[i]]) % MOD;
dp[i][j] = (dp[i][j] + v + dp[i - ][j + a[i]]) % MOD; }
}
int ans = ;
// printf("dds = %d %d\n",dp[3][5],dp[3][3]);
for(int i = ; i <= N; ++i) ans = (ans + dp[i][ + _max]) % MOD;
printf("%d\n",ans); } int main()
{
scanf("%d",&N);
for(int i = ; i <= N; ++i) {
scanf("%d",&a[i]);
//printf("%d \n",a[i]);
_max += a[i];
} solve();
return ;
}
cf 383 D的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
随机推荐
- spring 方法注入
package com.haut.grain.junit.test; public class Command {private Object state;public void setState( ...
- [Environment Build] Win10下Appach配置
1. Apache下载,登录http://httpd.apache.org/download.cgi,选择Files for Microsoft Windows, 有以下几个选择, 我选择的是Apac ...
- hdu 5281 Senior's Gun
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...
- Oracle12C的EM无法访问怎么办?
装完Oracle 12c,想体验下EM Express,缺发现不能用,应该怎么办?12c的EM 不再像以前版本配置那么麻烦,当然提供的功能也没有那么多了,只需要启用对应端口即可,请看:To manua ...
- Ubuntu无值守安装mysql
1. 使用apt-get -d install 命令下载安装包, 其中-d表示下载不安装. 下载后的deb包放在/var/cache/apt/archives目录 2. 使用dpkg-preconfi ...
- iOS学习之UIView
一.UI编程概述 1.UI的本意是用户界面,是英文User和Interface的缩写. 2.UI设计则是指对软件的人机交互.操作逻辑.界面美观的整体设计. 3.软件设计可 ...
- mac下的ssh自动登陆
终端的ssh是标准的OpenSSH client 如果需要克隆会话功能,可以通过配置打开. $ cat .ssh/config Host * ControlMaster auto ControlPat ...
- 2 通过JNI混合使用Java和C++ -----> 访问数组
关于c和cpp实现native方法的一些注释: 1> 在jni.h中首先定义了C的实现方式,然后用内联函数实现了Cpp的实现方式,如下所示: const char* GetStringUTFC ...
- disable_irq()与disable_irq_nosync()区别
disable_irq关闭中断并等待中断处理完后返回, 而disable_irq_nosync立即返回.
- 编译QT时出现lib/libQtGui.so: undefined reference to `ts_read_raw'的解决办法
lib/libQtGui.so: undefined reference to `ts_read_raw' /lib/libQtGui.so: undefined reference to `ts_o ...