题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <=…
题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <=…
题意:n颗硬币 两个人从前往后按顺序拿 如果上一个人拿了i颗 那么下一个可以拿1-2*i颗 问先手能获得的最大收益 题解:比较典型的最大最小最大最小..DP了 但是暴力做的话是n^3 所以就体现出了这个题的巧妙之处  dp[i][j]表示拿到了第i颗上一个人拿了j颗 dp[i][j]由 dp[i + k][k] k = 1,2...2 * j转移来 dp[i][j - 1]由 dp[i + k][k] k = 1,2...2 * (j - 1)转移来 有许多状态是一样的 所以dp[i][j-1]…
https://daniu.luogu.org/problemnew/show/P2964 dp[i][j] 表示桌面上还剩i枚硬币时,上一次取走了j个的最大得分 枚举这一次要拿k个,转移到dp[i-k][k] dp[i][j]=max(sum[i]-dp[i-k][k]) 因为 上一次取走j个和取走j-1个 k的取值范围 只相差 2*j-1 和 2*j 所以 直接 dp[i][j]=dp[i][j-1] 然后k分别等于  2*j-1 和 2*j,转移 最后输出dp[n][1],因为先手可以拿1…
题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <=…
题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <=…
洛谷 1938  [USACO09NOV]找工就业Job Hunt 题目描述 Bessie is running out of money and is searching for jobs. Farmer John knows this and wants the cows to travel around so he has imposed a rule that his cows can only make D (1 <= D <= 1,000) dollars in a city be…
很久很久之前做过的一道题 翻n-1枚硬币,就是有一枚不翻,也可以理解为翻一枚 直接上程序,看程序说话 #include<iostream> using namespace std; ; bool a[maxn];//a数组负责存储硬币的状态 int n;//n枚硬币 int main(){ cin>>n; cout<<n<<endl;//因为相当于只翻一枚,所以翻n次即可 ;i<=n;i++){//i表示这是第几次翻 ;j<=n;j++)//表示…
洛谷题目传送门 我实在是太弱了,第一次正儿八经写背包DP,第一次领会如此巧妙的容斥原理的应用...... 对每次询问都做一遍多重背包,显然T飞,就不考虑了 关键就在于每次询问如何利用重复的信息 我这么弱,当然是想不到容斥原理的啦 暂且先当成完全背包,每种硬币可使用无限次,预处理\(f\)数组,\(f[i]\)等于买价值\(i\)的东西的总方案数 然后就要从中减去不合法的.首先肯定会有一种硬币超额使用,第\(j\)中硬币等于说强制选了\(d_j+1\)个,剩下的依然随便选,那么第 \(j\)种硬币…
题面 洛谷 题解 \(f[i][j]\)表示有i个人参与游戏,从庄家(即1)数j个人获胜的概率是多少 \(f[1][1] = 1\) 这样就可以不用讨论淘汰了哪些人和顺序 枚举选庄家选那张牌, 枚举下一次的庄家 可以得到这次的庄家 然后转移即可 Code #include<bits/stdc++.h> #define LL long long #define RG register using namespace std; template<class T> inline void…