A POJ 1018 Communication System
B POJ 1050 To the Max
C POJ 1083 Moving Tables
D POJ 1125 Stockbroker Grapevine
E POJ 1143 Number Game
F POJ 1157 LITTLE SHOP OF FLOWERS
G POJ 1163 The Triangle
H POJ 1178 Camelot
I POJ 1179 Polygon
J POJ 1189 钉子和小球
K POJ 1191 棋盘分割
L POJ 1208 The Blocks Problem
M POJ 1276 Cash Machine
N POJ 1322 Chocolate
O POJ 1414 Life Line
P POJ 1456 Supermarket
Q POJ 1458 Common Subsequence
R POJ 1609 Tiling Up Blocks
S POJ 1644 To Bet or Not To Bet
T POJ 1664 放苹果
U POJ 1690 (Your)((Term)((Project)))
V POJ 1699 Best Sequence
W POJ 1740 A New Stone Game
X POJ 1742 Coins
Y POJ 1887 Testing the CATCHER
Z POJ 1926 Pollution

点击题号进入题面

---

A

/*
dp[i,j]
i个设备
j最小带宽
只能转移到dp[i-1][j]+大于等于j带宽的设备
*/
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
using namespace std;
const int maxn=1e3+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
int dp[maxn][maxn];
int num[maxn];
int p[maxn][maxn],f[maxn][maxn];
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif cin>>casn;
while(casn--){
int mx=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>num[i];
for(int j=1;j<=num[i];j++){
cin>>f[i][j]>>p[i][j];
mx=max(f[i][j],mx);
}
}
memset(dp,0,sizeof dp);
for(int i=1;i<=n;i++){
for(int j=0;j<=mx;j++){
int mn=INF;
for(int k=1;k<=num[i];k++){
if(j<=f[i][k]){
mn=min(dp[i-1][j]+p[i][k],mn);
}
}
dp[i][j]=mn;
}
}
double ans=0;
for(int i=1;i<=mx;i++){
ans=max(ans,i/(double)dp[n][i]);
}
printf("%.3f\n",ans);
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

B

/*
把二维看成一维
先枚举行的起点和终点
再把起点行和终点行间每一列的数值压缩到每一个点上
然后求一个最长连续字段和
复杂度O(n^3)
*/
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e3+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
#define ll long long
int casn,n,m,k;
int smax(int a[],int len){
int mx=0,sub=0;
for(int i=1;i<=len;i++){
sub=max(a[i],sub+a[i]);
mx=max(sub,mx);
}
return mx;
}
int arr[maxn];
int dp[maxn][maxn];
int main(){
#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif while(~scanf("%d",&n)){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&dp[i][j]);
}
}
int ans=-INF;
for(int i=1;i<=n;i++){
memset(arr,0,sizeof arr);
for(int j=i;j<=n;j++){
for(int k=1;k<=n;k++){
arr[k]+=dp[j][k];
}
ans=max(ans,smax(arr,n));
}
}
printf("%d\n",ans);
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

C

/*
交叉的工作是必须要完成的
而所有的不交叉工作都可以同时完成
那最晚完成的就是交叉次数最多的走廊区域了
注意由于走廊是公用的,所以南北的房间实际上一样
映射到1-200的区域就行了
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=1e3+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
int cost[maxn];
int main(){
// #define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif scanf("%d",&casn);
while(casn--){
scanf("%d",&n);
memset(cost,0,sizeof cost);
for(int i=1;i<=n;i++){
int x,y;
scanf("%d%d",&x,&y);
if(x>y) swap(x,y);
x=(x>>1)+(x&1);
y=(y>>1)+(y&1);
for(int j=x;j<=y;j++){
cost[j]++;
}
}
int ans=0;
for(int i=1;i<=400;i++){
ans=max(cost[i],ans);
}
printf("%d\n",ans*10);
} #ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

D

/*
有向图的floyd
跑完之后枚举一遍起点
保存最小最长边
输出的时候特判一下
*/
#include <string.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int maxn=1e2+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
int num[maxn];
int dp[maxn][maxn];
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif while(scanf("%d",&n),n){
memset(dp,INF,sizeof dp);
for(int i=1;i<=n;i++){
scanf("%d",&num[i]);
for(int j=0;j<num[i];j++){
int a,b;
scanf("%d%d",&a,&b);
dp[i][a]=b;
}
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
int t=dp[i][k]+dp[k][j];
dp[i][j]=min(dp[i][j],t);
}
}
}
int flag=0,ans=INF,id=0;
for(int i=1;i<=n;i++){
int t=0;
for(int j=1;j<=n;j++){
if(i==j) continue;
t=max(t,dp[i][j]);
}
if(t<ans) id=i,ans=t;
}
if(!id) puts("disjoint");
else printf("%d %d\n",id,ans);
} #ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

E

/*
如果i在list里,则进行dfs
如果dfs可以推出失败.则保存答案
dfs:
状态很显然是20个数字那些不能选
状态种类不多且每个状态只有2种情况
考虑状态压缩,每一位保存该位置的数字是否可以使用
用记忆化搜索,标记2进制所保存的状态的输赢
不断dfs,换选手,返回下一个选手是输还是赢即可
如果下一个选手输,则当前为必胜态,以此类推
*/
#include <string.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int maxn=2e6+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
int num[30];
int dp[maxn];
bool vis[30];
int ans[30];
int cps(bool vis[]){
int stt=0;
for(int i=2;i<=20;i++){
stt|=vis[i];
stt<<=1;
}
return stt>>1;
}
bool dfs(int now,bool vis[]){
bool vis2[30];
memcpy(vis2,vis,25);
vis2[now]=false;
for(int i=2;i+now<=20;i++){
if(!vis2[i])vis2[i+now]=false;
}
int stt=cps(vis2);
if(dp[stt]){
return dp[stt]>0;
}
for(int i=2;i<=20;i++){
if(vis2[i]&&!dfs(i,vis2)) return dp[stt]=1;
}
dp[stt]=-1;
return false;
}
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
memset(dp,0,sizeof dp);
while(scanf("%d",&n),n){
memset(vis,0,sizeof vis);
for(int i=1;i<=n;i++){
scanf("%d",&num[i]);
vis[num[i]]=true;
}
int cnt=0;
int stt=cps(vis);
for(int i=2;i<=20;i++){
if(vis[i]&&!dfs(i,vis)) ans[cnt++]=i;
}
printf("Test Case #%d\n",++casn);
if(cnt){
printf("The winning moves are:");
for(int i=0;i<cnt;i++){
printf(" %d",ans[i]);
}
puts("");
}else dp[stt]=-1,puts("There's no winning move.");
puts("");
} #ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

  

专题:DP杂题1的更多相关文章

  1. dp杂题(根据个人进度选更)

    ----19.7.30 今天又开了一个新专题,dp杂题,我依旧按照之前一样,这一个专题更在一起,根据个人进度选更题目; dp就是动态规划,本人认为,动态规划的核心就是dp状态的设立以及dp转移方程的推 ...

  2. 贪心/构造/DP 杂题选做Ⅱ

    由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...

  3. 贪心/构造/DP 杂题选做Ⅲ

    颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...

  4. 一些DP杂题

    1. [HNOI2001] 产品加工 一道简单的背包,然而我还是写了很久QAQ 时间范围是都小于5 显然考虑一维背包,dp[i]表示目前A消耗了i的最小B消耗 注意 if(b[i]) dp[j]=dp ...

  5. 【做题记录】DP 杂题

    P2577 [ZJOI2004]午餐 $\texttt{solution}$ 想到贪心: 吃饭慢的先打饭节约时间, 所以先将人按吃饭时间从大到小排序. 状态: \(f[i][j]\) 表示前 \(i\ ...

  6. 贪心/构造/DP 杂题选做

    本博客将会收录一些贪心/构造的我认为较有价值的题目,这样可以有效的避免日后碰到 P7115 或者 P7915 这样的题就束手无策进而垫底的情况/dk 某些题目虽然跟贪心关系不大,但是在 CF 上有个 ...

  7. DP杂题2

    1.邦邦的大合唱站队 https://www.luogu.org/problem/show?pid=3694 XY说这是道简单的签到题,然后我大概是普及组都拿不到三等的那种了.. 插入题解.写得太好了 ...

  8. 【模拟8.01】matrix(DP杂题,思维题)

    很神的题,感谢lnc大佬的指点. 先设1-LL[i]统称左区间,RR[i]-m为右区间 用L[i]统计从1-i列,出现的左区间端点的前缀和,R[i]是右区间.... f[i][j]中j表示当前在第i列 ...

  9. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

随机推荐

  1. sqlserver修改计算机名称。

    SELECT @@SERVERNAME As [@@SERVERNAME], CAST(SERVERPROPERTY('MACHINENAME') AS VARCHAR(128)) + COALESC ...

  2. Linux学习笔记:【004】Linux内核代码风格

    Chinese translated version of Documentation/CodingStyle   If you have any comment or update to the c ...

  3. Chrome Dev Tools: Code Folding in CSS and Javascript for improved code readiability

    Note : Apply for google chrome canary. You can fold code blocks in CSS (and Sass) and javascript fil ...

  4. java基础之反射---重要

    java反射: 反射是框架设计的灵魂 (使用的前提条件:必须先得到代表的字节码的Class,Class类用于表示.class文件(字节码)):   1:获取Class字节码文件对象的三种方式: /** ...

  5. Android studio在新窗口中打开新项目

  6. Redis基础知识 之——发布/订阅

    一.说明: 订阅,取消订阅和发布实现了发布/订阅消息范式(引自wikipedia),发送者(发布者)不是计划发送消息给特定的接收者(订阅者).而是发布的消息分到不同的频道,不需要知道什么样的订阅者订阅 ...

  7. [译]C#7 Pattern Matching

    原文 public struct Square { public double Side { get; } public Square(double side) { Side = side; } } ...

  8. IDApython教程(一)

    IDAPython是IDA的一个功能强大的扩展特性,对外提供了大量的IDA API调用.另外,还能在使用python 脚本语言的过程中获得能力提升,所以我强烈推荐所有的逆向工程师使用它. 然而不幸的是 ...

  9. python 爬虫得到网页的图片

    import urllib.request,os import re # 获取html 中的内容 def getHtml(url): page=urllib.request.urlopen(url) ...

  10. Docker 容器启动 查看容器状态 - 四

    1.容器两种方式进行启动 一种是基于创建一个容器并启动 docker create docker start 另一种 使用 run 创建自动启动:是状态下的停止 启动 docker start ngi ...