5 November
拓扑排序
for (int i=1; i<=n; ++i) if (!ind[i]) q.push(i);
while (!q.empty()) {
int now=q.top(); q.pop(); printf("%d ", now);
for (int k=head[now]; k; k=nex[k])
if (--ind[to[k]]==0) q.push(to[k]);
}
神奇の背包 DP
现有 \(N\) 个物品和容积为 \(M\) 的背包. 物品的体积分别为 \(V_1, V_2, ..., V_N\). 求不选取物品 \(i\) 时, 装满背包的方案数量.
设 \(f(n, V)\) 为正向枚举的背包, \(g(n, V)\) 为反向枚举的背包, 则方案数为 \(\displaystyle \sum_{i=1}^{n}\sum_{j=0}^{m} f(i-1, j)\cdot g(i+1, m-j)\).
本次错误在于没有搞明白1维和2维背包的代码异同点:1维背包已经无需直接赋值,2维背包还是需要 \(f(i, j)=f(i-1, j)\) 的。
#include <cstdio>
int n, m, w[1003], f[1003][10003], g[1003][10003], ans;
int main() {
scanf("%d%d", &n, &m);
for (int i=1; i<=n; ++i) scanf("%d", &w[i]);
f[0][0]=1;
for (int i=1; i<=n; ++i) {
for (int j=m; j>=w[i]; --j) f[i][j]=(f[i-1][j]+f[i-1][j-w[i]])%1014;
for (int j=w[i]-1; ~j; --j) f[i][j]=f[i-1][j]; // (*)
}
g[n+1][0]=1;
for (int i=n; i; --i) {
for (int j=m; j>=w[i]; --j) g[i][j]=(g[i+1][j]+g[i+1][j-w[i]])%1014;
for (int j=w[i]-1; ~j; --j) g[i][j]=g[i+1][j]; // (*)
}
for (int i=1; i<=n; ++i) {
ans=0;
for (int j=0; j<=m; ++j) ans=(ans+f[i-1][j]*g[i+1][m-j])%1014;
printf("%d ", ans);
}
return 0;
}
Sequence
给出数列 \(\{A_n\}\), 修改最少的元素, 使得数列 \(\{A_n\}\) 成为一个公差为 1 的等差数列.
预处理成数列 \(\{A_n-n\}\) 即可极大简化本题解法.
5 November的更多相关文章
- [POJ1765]November Rain
[POJ1765]November Rain 试题描述 Contemporary buildings can have very complicated roofs. If we take a ver ...
- We will be discontinuing the Nitrous Development Platform and Cloud IDE on November 14th, 2016.
我表示我很难过 Nitrous We will be discontinuing the Nitrous Development Platform and Cloud IDE on November ...
- TIOBE Index for November 2015(转载)
原文地址:http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html November Headline: Java once a ...
- 日常英语---七、[Updated November 14 at 4:10 PM PST] Scheduled Game Update - November 14, 2018(n.标准)
日常英语---七.[Updated November 14 at 4:10 PM PST] Scheduled Game Update - November 14, 2018(n.标准) 一.总结 一 ...
- Multi-Cloud & Kubernetes: Cloud Academy November 2018 Data Report
https://cloudacademy.com/research/multi-cloud-kubernetes-devops-cloud-academy-data-report-nov-18/ No ...
- ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010
ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbil ...
- USACO 2006 November Gold Corn Fields
USACO 2006 November Gold Corn Fields 题目描述: Farmer John has purchased a lush new rectangular pasture ...
- November 3rd Week 45th Thursday 2016
Shared joy is a double joy, the same as your gift and idea. 与人分享,欢乐.灵感加倍. As a coder, I must work wi ...
- November 1st 2016 Week 45th Tuesday
Difficult circumstances serve as a textbook of life for people. 艰难坎坷是人们的生活教科书. It would be better if ...
- November 2nd Week 45th Wednesday 2016
If your ship doesn't come in, swim out to it. 如果你的船不驶进来,那你就朝他游过去吧! Swim out to it, don't fear that y ...
随机推荐
- eclipse maven 项目突然所有的JS方法都失效了
原因:JS 或者 jQuery 有严重的语法错误
- 创建React脚手架
node版本10.14.2 下载地址 如果是其版本的话会出错 css-loader 会不兼容 主要是8.x的版本不兼容 npm install -g create-react-app 全局安装 cre ...
- list 转 map java8
// Arrays.asList("a:1.0", "b:2.0", "c:3.0") --> Map {a=1.0, b=2.0, ...
- 02: CI(持续集成)/CD(持续交付/持续部署)
1.1 持续集成.持续交付 介绍 参考博客:https://www.cnblogs.com/cay83/p/8856231.html 1.传统交付 1. 传统软件的开发与交付的周期都很漫长,从需求 ...
- linux 环境 Xshell操作数据库
一:采用sqlplus连接登录(确保安装了sqlplus) 1:先登陆进入到oracle的数据库的服务器环境下 2:切换到sqlplus操作: sqlplus /nolog 3:conn /as s ...
- Neo4j源代码分析
1.下载neo4j源码 https://github.com/neo4j/neo4j/ 参考文章 原文地址:https://blog.csdn.net/e15273/article/details/7 ...
- 在Visual studio 2017中使用EF6连接MySQL
在Visual studio 2017中使用EF6连接Mysql ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) ...
- react找到对象数组中指定的值
找到对象数组中指定的值var array = [ { label: "Custom", value: "0" }, ...
- Mysql 服务器管理程序 mysqladmin
mysqladmin [oprions] command 选项 说明 create db_name ...
- [ZJOI2006]物流运输(动态规划,最短路)
[ZJOI2006]物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个 ...