题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt's friends has a magic number. In the game, Matt selects some (could be zero) of his friends. If the xor (exclusive-or) sum of the selected friends'ma…
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值,其中第i个子序列包括a[j], 则max(dp[m][k]),m<=k<=n 即为所求的结果 <2>初始状态: dp[i][0] = 0, dp[0][j] = 0; <3>状态转移: 决策:a[j]自己成为一个子段,还是接在前面一个子段的后面 方程: a[j]直接接在前面…
Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 47440   Accepted: 20178 Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible fro…
Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Others) Total Submission(s): 700 Accepted Submission(s): 270 Problem Description Matt has N friends. They are playing a game together. Each of Matt's friend…
算法笔记(c++)--关于01背包的滚动数组 关于01背包问题:基本方法我这篇写过了. https://www.cnblogs.com/DJC-BLOG/p/9416799.html 但是这里数组是N^2,据说滚动数组可以用1维来代替二维. 我想了想也没想通.干脆老方法,一步步列出来就懂了. 先上下滚动数组的代码,然后分析代码: dp[N];//这里只用一维的 ; i<=n; i++)//对每个数判断,可反 { for(int j=m; j>=weight[i]; j--)/ dp[j]=ma…
题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio.h> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <memory> #include <iostream>…
题目大意: 输入n,s:n头牛 s个栅栏 输入n头牛的初始位置 改变他们的位置,满足 1.第一头与最后一头的距离尽量大 2.相邻两头牛之间的距离尽量满足 d=(s-1)/(n-1),偏差不超过1 3.移动的总步数尽量小 https://blog.csdn.net/BlackJack_/article/details/73527208 首先因需要尽量满足d 1.若整除则全部为d即可 2.若不整除则说明存在偏差,则有些距离 d 有些距离 d+1 即可 除了第一头牛移到1 最后一头牛移到s之外 其余第…
Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 510000/510000 K (Java/Others)Total Submission(s): 5188    Accepted Submission(s): 1985 Problem Description Matt has N friends. They are playing a game together. Each of Matt’s…
虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[i]] + dp[i - 1][j]; dp[i][j] 的意思是,对于数列 中前 i 个数字,使得 XOR 和恰好为 j 的方案数 状态转移方程中的 dp[i - 1][j] 即表示当前这个数字不取, dp[i - 1][j ^ a[i]] 表示当前这个数字要取. 这道题还是要好好理解阿! sou…
题意:有最多40个数字,取任意个数字他们的异或和>=k则是可行的方案,问有多少种可行的方案. 分析:dp[now][j]表示当前这个值的种类数,那么转移方程为dp[now][j] = dp[pre][j] + dp[pre][j^a[i]].因为a^b=c的话,c^b=a,所以j^a[i]就可以得到通过异或a[i]转移到j的那个状态了.然后可以用滚动数组压缩一下. 代码如下: #include <stdio.h> #include <algorithm> #include &…