拓扑排序

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的更多相关文章

  1. [POJ1765]November Rain

    [POJ1765]November Rain 试题描述 Contemporary buildings can have very complicated roofs. If we take a ver ...

  2. 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 ...

  3. TIOBE Index for November 2015(转载)

    原文地址:http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html November Headline: Java once a ...

  4. 日常英语---七、[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.标准) 一.总结 一 ...

  5. Multi-Cloud & Kubernetes: Cloud Academy November 2018 Data Report

    https://cloudacademy.com/research/multi-cloud-kubernetes-devops-cloud-academy-data-report-nov-18/ No ...

  6. 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 ...

  7. USACO 2006 November Gold Corn Fields

    USACO 2006 November Gold Corn Fields 题目描述: Farmer John has purchased a lush new rectangular pasture ...

  8. 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 ...

  9. November 1st 2016 Week 45th Tuesday

    Difficult circumstances serve as a textbook of life for people. 艰难坎坷是人们的生活教科书. It would be better if ...

  10. 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 ...

随机推荐

  1. [百家号]APT组织简介2019

    5家新APT组织被披露,2019是“后起之秀”的天下? https://baijiahao.baidu.com/s?id=1621699899936470038&wfr=spider& ...

  2. 关于this与e.target区别以及data-*属性

    1 this与event.target 在编写事件函数时可以传入一个event参数,even参数可以使用一个target属性如even.target用以调用,其作用是指向返回事件的目标节点(触发该事件 ...

  3. ARM之cache

    一. 什么是cache 1.1. cache简介 a. Cache 即高速缓冲存储器,是位于 CPU 与内存之间的高速存储器,它的容量比内存小但交换速度快. b. ARM处理器的主频为上百M甚至几G, ...

  4. htpwdScan — 一个简单的HTTP暴力破解、撞库攻击脚本

    李姐姐之前跟我们分享了子域名枚举工具subDomainBrute<subDomainsBrute — 改进渗透测试时暴力枚举子域名的python脚本>,这回带给我们htpwdScan ht ...

  5. tornado + nginx + supervisord 环境部署

    学习tornado有一周多了,自己按着demo中的例子手动搬代码,收获还是有的,加深了理解.demo: http://demo.pythoner.com/itt2zh/ch8.html 大概明白了它怎 ...

  6. 广播即时通信src和des

    package 第十二章; import java.io.IOException; import java.net.DatagramPacket; import java.net.InetAddres ...

  7. Hive内部表,外部表和分区表

    外部表和内部表的区别 内部表也称之为managed_table: 默认存储在/user/hive/warehouse下,也可以通过location指定: 删除表事,会删除表数据以及元数据: 外部表称之 ...

  8. UIScrollView学习笔记

    1.如何使用UIScrollView显示一张比屏幕大的图片 //创建滚动视图的对象 UIScrollView * sv = [[UIScrollView alloc]initWithFrame:CGR ...

  9. delete释放空间时出错的原因

    int *a=new int[10]; ...... delete []a; 后面“delete []a;”出现错误的情况大致有: 1 数组的首地址a被你有意无意更改了,如:a++之类的: 2 变量的 ...

  10. 客户端远程连接docker容器中的mysql 报1251错误

    1.启动容器: [root@localhost ~]# docker run -d -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql2.进入容器: [r ...