URAL 1244. Gentlemen(DP)】的更多相关文章

题目链接 这题不难啊...标记一下就行了.表示啥想法也没有. #include <cstring> #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <cmath> #include <map> using namespace std; #define INF 100000000 ]; ]; ]; ];…
题目传送门 /* 题意:已知丢失若干卡片后剩余的总体积,并知道原来所有卡片的各自的体积,问丢失的卡片的id DP递推:首先从丢失的卡片的总体积考虑,dp[i] 代表体积为i的方案数,从dp[0] = 1递推,累加的条件是dp[j]上一个状态已经有方案, 若dp[w] > 1表示有多种方案,外加p[j+a[i]] = i的记录路径数组 我开始用了暴力DFS超时,dp不会写,看了题解发现是个递推,有点像01背包的题目:) 详细解释:http://blog.csdn.net/neko01/articl…
题目传送门 /* 题意:给出少了若干卡片后的总和,和原来所有卡片,问少了哪几张 DP:转化为少了的总和是否能有若干张卡片相加得到,dp[j+a[i]] += dp[j]; 记录一次路径,当第一次更新的时候 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <vector>…
1244. Gentlemen Time limit: 0.5 secondMemory limit: 64 MB Let's remember one old joke: Once a gentleman said to another gentleman:— What if we play cards?— You know, I haven't played cards for ten years…— And I haven't played for fifteen years…So, li…
题目链接 题意 : 给出一幅不完全的纸牌.算出哪些牌丢失了. 思路 : 算是背包一个吧.if f[j]>0  f[j+a[i]] += f[j];然后在记录一下路径. #include <stdio.h> #include <string.h> #include <iostream> using namespace std ; ] ,b[]; ] ; int main() { int w ; while(~scanf("%d",&w))…
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 题目大意:树枝上间连接着一坨坨苹果(不要在意'坨'),给定留下m根树枝,问最后剩下的最多苹果是多少. 解题思路: 其实意思和Vijos 1180(选课)的意思差不多.只不过权在边而已. 首先建无向图dfs. for(f+1...j....cost) for(1....k...j-cost) 其中f为当前已经dfs子结点个数.之所以+1,是因为当前点也需要…
http://acm.timus.ru/problem.aspx?space=1&num=1039 1039. Anniversary Party Time limit: 0.5 secondMemory limit: 8 MB Background The president of the Ural State University is going to make an 80'th Anniversary party. The university has a hierarchical st…
题目链接 我用的比较传统的办法...单调队列优化了一下,写的有点搓,不管怎样过了...两个单调队列,存两个东西,预处理一个标记数组存... #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <map> #include <ctime> #include <cmath> #include <algorit…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 思路:典型的树形dp,处理的时候类似于分组背包,dp[i][j]代表以i为根的树取j个分支获得的最大值. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> using name…
题目大意:给出一个正整数M,给出N个正整数ai,让你在这些数中挑出一些数组成M的一个划分,如果符合条件的划分数超过两个,输出:-1,如果没有输出:0,如果有且仅有一个:则按顺序输出剩下的数的序号. 例如: input output 270 4 100 110 170 200 2 4 270 4 100 110 160 170 -1 270 4 100 120 160 180 0 测例1中,有且仅有100+170=270,所以输出110与200的序号2 4.测例2中,100+170=160+110…