摘要: 首先要考虑两个人的策略分别是什么,显然A每次要吃最小的蛋糕,B要么不吃,要么就把一种类的蛋糕全部吃完。所以也是动态规划dp[i][j]表示吃第i种蛋糕,B吃了j次后x的最小值 `#include<bits/stdc++.h> using namespace std; define int long 阅读全文
posted @ 2025-02-16 20:27 十柒* 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 动态规划,dp[i][j],j=0/1表示此人说真话还是假话,因为说谎者的数据不可信,所以转移时没有任何条件dp[i][1]=dp[i-1][0];而说真话的人有两种情况,前一个人说真话或者说假话,分开讨论,最后结果就是dp[n][0]+dp[n][1]; `#include<bits/stdc++ 阅读全文
posted @ 2025-02-16 20:22 十柒* 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 将第一个序列标号,所以序号和值就相互映射,再将第二个序列用映射转变一下,最后只要求转变后的序列的最长上升子序列就行了,求lis只要维护一个单调递增的栈,大于栈首就入栈,小于栈首就用二分查找替换最小的大与它的数 `#include include include include<math.h> usi 阅读全文
posted @ 2025-02-16 20:17 十柒* 阅读(0) 评论(0) 推荐(0) 编辑
摘要: 将m个宝物一一拆开,就是普通的0-1背包问题,但是这样会超时,所以想到用二进制拆分m,最后再当做0-1背包问题 `#include include include include<math.h> using namespace std; const int N=2e7+7; int w,n; int 阅读全文
posted @ 2025-02-16 20:11 十柒* 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 最基础的0-1背包问题,没什么好说的 `#include include include include<math.h> using namespace std; const int N=2e5+7; int t,m; int lst[107][2]; int memory[107][1007]={ 阅读全文
posted @ 2025-02-16 20:08 十柒* 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 只要维护一个dp[i]就行了,dp[i]表示以i结尾的最大字段和,要么是第i个数本身,要么是第i个数加上dp[i-1],只要dp[i-1]>0,那么就肯定是后者 `#include const int N=2e5+7; int main(){ int n,lst[N]={0}; scanf("%d" 阅读全文
posted @ 2025-02-16 20:06 十柒* 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 典型的八皇后问题,用回溯遍历每一种情况,当前格子能放皇后就放,直到剩余皇后数量为0输出情况。而判断是否能放就是判断当前位置的横,竖,左斜,右斜是否有皇后,横竖都好判断,而左斜的位置index的和相等,右斜的位置index差相等。 `#include<stdio.h> include<string.h 阅读全文
posted @ 2025-02-13 22:44 十柒* 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 遍历整个二维数组,将数字相同的都入队,然后标记已经处理过,接着开始处理,判断每个位置是否都比相邻的不同高的位置高或低,就可以判断这些数是否为山谷或山峰 `#include include int que[1000007][3]; int m1[8]={-1,-1,-1,0,0,1,1,1},m2[8 阅读全文
posted @ 2025-02-13 22:39 十柒* 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 通过回溯搜索满足第一种维他命的情况,然后用这种情况检验其余维他命是否满足 `#include int v,lst[27],g,lst_v[17][27],p=0,f=1; int index[17]={0}; int My_sum(int n){ int sum=0; for(int i=0;i<g 阅读全文
posted @ 2025-02-13 22:35 十柒* 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 以每一个1为起点向外搜索,不断更新最近距离,如果不能更新则剪枝,不然会超时 `#include int n,m; char a; int m1[4]={-1,1,0,0},m2[4]={0,0,-1,1}; struct q1{ int i,j; int d=0; } q_bai[2000007]; 阅读全文
posted @ 2025-02-13 22:33 十柒* 阅读(1) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示