poj 3671 Dining Cows (Dp)】的更多相关文章

/* 一开始并没有想出On的正解 后来发现题解的思路也是十分的巧妙的 还是没能把握住题目的 只有1 2这两个数的条件 dp还带练练啊 ... */ #include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 using namespace std; int n,a[maxn],Q[maxn],H[maxn],ans=0x7fffffff; int main() { scanf(&qu…
题意:给定 n 个数,让你修改最少的数,使得这是一个不下降序列. 析:和3670一思路,就是一个LIS,也可以直接暴力,因为只有两个数,所以可以枚举在哪分界,左边是1,右边是2,更新答案. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #includ…
Dining Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7584   Accepted: 3201 Description The cows are so very silly about their dinner partners. They have organized themselves into two groups (conveniently numbered 1 and 2) that ins…
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others. Farmer John has cooked fabulous meals for his cows, but he forgot to check his menu against their…
缩点练习 洛谷 P3387 [模板]缩点 缩点 解题思路: 都说是模板了...先缩点把有环图转换成DAG 然后拓扑排序即可 #include <bits/stdc++.h> using namespace std; /* freopen("k.in", "r", stdin); freopen("k.out", "w", stdout); */ //clock_t c1 = clock(); //std::cerr…
主题链接: 啊哈哈,点我点我 题意: 给一个仅仅含有1.2的序列,如何变换n次使序列成为一个非递减的序列,而且使n最小. 思路: 这道题的数据范围是50000,则肯定承受不了n方的复杂度.所以 仅仅能写O(n)的算法,甚至更小,所以当时想二分,可是不知道怎么写,忽然想到能够枚举每个位置,把每个位置都当做一个分界点.然后求前半部有多少个2.后半段有多少个1,最后和所有是1和2进行比較,这个问题便得到了解决. 题目: Dining Cows Time Limit: 1000MS   Memory L…
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/problem.php?pid=586 poj : http://poj.org/problem?id=2456 思路: 二分答案,从前到后依次排放m头牛的位置,检查是否可行 代码: #include <iostream> #include <algorithm> #include &…
POJ 2456 Agressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2≤N≤100,000)个隔间,这 些小隔间的位置为x0,...,xN-1 (0≤xi≤1,000,000,000,均为整数,各不相同). John的C (2≤C≤N)头牛每头分到一个隔间.牛都希望互相离得远点省得 互相打扰.怎样才能使任意两头牛之间的最小距离尽可能的大,这个最 大的最小距离是多少呢 思想:二分,首先把输入的数据进行从小到大排序,再由最短距离为1,最长距离为(a[n-1] - a[0…
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 13000 #define nnmax 3500 using namespace std; int dp[nmax]; int w[nnmax],d[nnmax]; int main…
POJ 3281 Dining id=3281" target="_blank" style="">题目链接 题意:n个牛.每一个牛有一些喜欢的食物和饮料.每种食物饮料仅仅有一个.问最大能匹配上多少仅仅牛每一个牛都能吃上喜欢的食物和喜欢的饮料 思路:最大流.建模源点到每一个食物连一条边,容量为1,每一个饮料向汇点连一条边容量为1,然后因为每一个牛有容量1.所以把牛进行拆点.然后食物连向牛的入点,牛的出点连向食物,跑一下最大流就可以 代码: #incl…
题目传送门 /* 二分搜索:搜索安排最近牛的距离不小于d */ #include <cstdio> #include <algorithm> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int x[MAXN]; int n, m; bool check(int d) { ; ; i<=m-; ++i) { ; while (cur <= n && x[…
poj 2186 Popular Cows 题意: 有N头牛, 给出M对关系, 如(1,2)代表1欢迎2, 关系是单向的且能够传递, 即1欢迎2不代表2欢迎1, 可是假设2也欢迎3那么1也欢迎3. 求被全部牛都欢迎的牛的数量. 限制: 1 <= N <= 10000 1 <= M <= 50000 思路: Kosaraju算法, 看缩点后拓扑序的终点有多少头牛, 且要推断是不是全部强连通分量都连向它. Kosaraju算法.分拆完连通分量后,也完毕了拓扑序. /*poj 2186…
POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间DP,以为就是用栈进行模拟呢,可是发现就是不大对,后来想到是不是使用DP,但是开始的时候自己没有推出递推关系,后来实在想不出来看的题解,才知道是区间DP,仔细一想确实是啊. 下面就是状态转移方程: \[ \begin{cases}dp[i][j] &=& dp[i+1][j-1]+if(str…
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time. The treats are interesting for…
开一个dp[30010][3]的数组 其中dp[i][j]表示把第i个数改成j最少要花多少次 那么状态转移方程就列出来了: 令a=1 j!=a[i] 0 j==a[i] 那么dp[i][1]=dp[i-1][1]+a; dp[i][2]=min(dp[i-1][1],dp[i-1][2])+a; 那么根据空间优化原理,我们的第一维的i不过是为了递推,那么可以优化掉. 不过要注意的是,dp[2]的状态要先求,否则测试数据会是3,因为沿用了本次的dp[1],而非上次的dp[1]. #include…
思路: 1.DP f[i][j]:前i个数 最后一个数是j的最小花费 f[i][j]=min(f[i][j],f[i-1][k]+(a[i]!=j));1<=k<=j 这种做法比较有普遍性- 2. 直接枚举断点乱搞不就行了嘛- 枚举在哪儿转折成的2 (注意全是1或者全是2的情况就OK了) //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespa…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8126   Accepted: 3441 Description The cows are so very silly about their dinner partners. They have organized themselves into two groups (conveniently numbered 1 and 2) that insist upon din…
题目链接:http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6548   Accepted: 3446 Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amount…
1.poj 3254  Corn Fields    状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相邻,求有多少种放法. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #d…
1.POJ 1260 2.链接:http://poj.org/problem?id=1260 3.总结:不太懂dp,看了题解 http://www.cnblogs.com/lyy289065406/archive/2011/07/31/2122652.html 题意:珍珠,给出需求,单价,要求用最少的钱就可以买到相同数量的,相同(或更高)质量的珍珠. 把握题意,1.输入时,后输入的珍珠价格一定比前面输入的要贵.2.用高质量珍珠替代低质量. #include<iostream> #include…
Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others. Farmer John has cooked fabulous meals for his cows, but he forgot to check his menu against their preferences. Al…
题目地址:http://poj.org/problem?id=1463 题目: Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 7929   Accepted: 3692 Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solu…
题目链接: http://poj.org/problem?id=1947 题目大意:树中各点都由一条边连接.问要弄出个含有m个点的(子)树,至少需要截去多少条边. 解题思路: 设dp[i][j]为i总根(注意是当前点为总根,不再考虑其父亲,这题是要在原来的树里面切出一个树),留下j个点截去的最少的边. 首先dp[i][1]=子结点数量,即只留下根,要把所有与子节点的边给截掉. 对于dp[i][2~m]:如果取子结点,则dp[i][j]=min(dp[i][j],dp[i][j-k]+dp[t][…
题目链接:http://poj.org/problem?id=1155 题目大意:电视台要广播电视节目,要经过中转机构,到观众.从电视台到中转商到观众是一个树形结构,经过一条边需要支付成本.现在给你每两个节点之间传播的成本,给你每个观众会付的钱,问你电视台在不亏本的情况下最多能给多少个观众看节目. 这是我的第一道树形dp..无耻的看了题解.. 设计状态:dp[u][i]代表以u为根的子树中有i个观众,能够得到的最大收入. 状态转移:dp[u][i] = max(dp[u][i],dp[u][i-…
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组成i的不同方案数,那么 dp[1]=1;dp[2]=2; if(i%2) dp[i]=dp[i-1] ;  i如果是奇数,那么只能在i-1的每个方案数前面加上1得到i,所以方案数相等. else dp[i]=dp[i-1]+dp[i/2] ;  i如果是偶数,一种可能是i有两个1,在i-1的每个方案…
题意: 裸的tsp. 分析: 用bfs求出随意两点之间的距离后能够暴搜也能够用next_permutation水,但效率肯定不如状压dp.dp[s][u]表示从0出发訪问过s集合中的点.眼下在点u走过的最短路程. 代码: //poj 2688 //sep9 #include <iostream> #include <queue> using namespace std; const int maxW=32; const int maxN=12; int dx[4]={-1,1,0,…
B - DiningTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88038#problem/B Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no oth…
http://poj.org/problem?id=2186 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20191   Accepted: 8193 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you…
Dining Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11828   Accepted: 5437 Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others. Farmer John has cooked fabulo…
题目直达车:   POJ 1185 炮兵阵地 分析: 列( <=10 )的数据比较小, 一般会想到状压DP. Ⅰ.如果一行10全个‘P’,满足题意的状态不超过60种(可手动枚举). Ⅱ.用DFS搜出所有可能表示状态的整数(二进制1表示可以放,0则不能). Ⅲ.对每一行的地行进行状态处理(p[i]表示第i行地形的状态),二进制‘H’转1,‘P’转0: Ⅳ.用dp[i][j][k]表示第i行,且i行状态为j,i-1行状态为k时,最多能放置的量. Ⅴ.对于第i行的可行状态必须满足: ⒈  j &…