题意:一个数组a[i],你可以挑出若干个数(只能挑一次)加起来等于k, 针对每一种方案,你可以选出这若干个数的子集来组合新数 最后所有的方案能组合出多少种数 分析:一看数据范围n,k<=500 那就是显而易见就是母函数那套了 从1到n,dp[i][j],代表通过前i个元素和为i,能否组合出j #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include…
题目大概说给n个各有价值的硬币,要从它们中选出若干个组合成面值k,而要求的是各个方案里这些选出的硬币能组合出来的面值有哪些. 有点绕.. dp[i][j][k]表示前i个硬币中 能否 组合成面值j且选出的硬币能组合成面值k 转移要考虑全面..三个方向转移,第i个不选.第i个选但不参与选出硬币去组合成k.第i个选且参与选出硬币去组成成k #include<cstdio> using namespace std; ][][]; int main(){ int n,K,a; scanf("…
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. 简单dp,dp[i]表示取i时zui最大和为多少,方程为dp[i] = max(dp[i - 1] , dp[i - 2] + cont[i]*i). #include <bits/stdc++.h> using namespace std; typedef __int64 LL; ; LL a…
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Noura Boubou is a Syrian volunteer at ACM ACPC (Arab Collegiate Programming Contest) since 2011. She graduated from Tishreen Un…
题目链接:http://codeforces.com/problemset/problem/687/C 题目大概说给n个各有价值的硬币,要从它们中选出若干个组合成面值k,而要求的是各个方案里这些选出的硬币能组合出来的面值有哪些. dp[i][j][k]表示到第i个硬币,组成面值为j,包含面值为k的方案数. 注意用滚动数组写. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm&g…
$dp$,背包. $f[i][j][s]$表示前$i$个物品,凑出$j$价格的情况下,能否凑出$s$价格,$f[i][j][s]=1$表示能,否则不能. 转移很简单:如果$f[i][j][s]=1$,那么$f[i+1][j][s]=1$,$f[i+1][j+c[i]][s]=1$,$f[i+1][j+c[i]][s+c[i]]=1$.最后将$f[n][k][s]=1$的$s$都输出就可以了. $f[500][500][500]$内存会炸,第一维可以用滚动数组优化. #pragma comment…
这个也可以说是一个01背包了,里面也有一些集合的思想在里面,首先dp方程,dp[i][j]代表着当前数值为i,j能否被构成,如果dp[i][j] = 1,那么dp[i+m][j] 和 dp[i+m][j+m] = 1,所以转移方程就写出来了,但是注意我们只能从后向前转移,也就是说我们一定要用选上一个数的状态,因为这里是01背包,每一个数只能选一次,如果正着选就是完全背包了. 代码如下: #include<iostream> #include<cstdio> #include<…
C. Writing Code Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/problem/C Description Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working o…
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅能向↖或↗走一步 求:最大的路径和 最后一行的哪个位置作为起点 从下到上的路径 思路: 简单dp #include <cstdio> #include <algorithm> #include<iostream> #include<string.h> #incl…
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the E…