我的涨分日记(一)——BestCoder Round #56
来源:互联网 发布:java连接url账号密码 编辑:程序博客网 时间:2024/05/17 08:33
hdu5463-Clarke and minecraft
题目大意我就不赘述了,在比赛的页面有中文版的题目
思路:一开始想复杂了,其实这个题是非常水的。开一个长度是500的数组,把每个种类的材料数目累积下来,然后扫一遍每64个的材料算作一格,不满一格的必须按一格算不可以和其他材料叠加。最后将所有的格数加起来,再每36格运一趟,不足一趟的按一趟算。
代码:
#include <iostream>#include <cstdio>#include <queue>#include <stack>#include <cstring>using namespace std;#define maxn 500+5#define clr(x,y) memset(x,y,sizeof(x))int ans[maxn];typedef long long ll;int main(){ int T,n,a,b; cin>>T; while(T--) { clr(ans,0); cin>>n; for(int i=0; i<n; i++) { scanf("%d %d",&a,&b); ans[a]+=b; } int ant=0; for(int i=1; i<=500; i++) if(ans[i]) { ant+=ans[i]/64; ans[i]%=64; if(ans[i])ant++; } int k=ant/36; ant%=36; if(ant)k++; cout<<k<<endl; } return 0;}
hdu5464-Clarke and problem
题意也不说了
思路:说实话,看题目的时候没看出来这是dp,看来我的动态规划要重新学习!
但是看完题解才发现这确实肯定是dp,部分数据给的这么小,而且满足最优子结构、无后效性。。。
那么令dp(i,j)表示用前i个数模p等于j的方案数,那么状态转移方程是dp(i,j)=dp(i-1,j)+dp(i-1,(j-a[i])mod p),注意这里状态转移方程与官方题解给的不一样(我觉得那个题解是错误的!)
解释是用前i个数模p等于j的方案数包括两个部分的内容:
一个是不取第i个数,那么就是用前i-1个数模p等于j的方案数
另一个是取第i个数,那么就是用前i-1个数模p等于(j-a[i])的方案数 (取模后为负数的定义我就不给出了)
代码:
#include <iostream>#include <cstdio>#include <queue>#include <stack>#include <cstring>using namespace std;#define maxn 1000+5#define clr(x,y) memset(x,y,sizeof(x))typedef long long ll;int p;ll a[maxn];ll d[maxn][maxn];ll dp(int i,int j){ if(d[i][j]>=0)return d[i][j]; if(!i) { if(!j)return d[i][j]=1; else return d[i][j]=0; } ll k=j-a[i]; if(k>=0) k%=p; else { ll h=-k/p; k+=(h+1)*p; k%=p; } return d[i][j]=(dp(i-1,j)+dp(i-1,k))%1000000007;}int main(){ int T,n; cin>>T; while(T--) { cin>>n>>p; clr(d,-1); for(int i=1;i<=n;i++) scanf("%lld",a+i); printf("%lld\n",dp(n,0)); } return 0;}
hdu5465-Clarke and puzzle
这题暂时不会,还需要回去把博弈论里的NIM取数游戏和树状数组复习一下。。。
争取这周周末把我自己的思路写上来。。。
0 0
- 我的涨分日记(一)——BestCoder Round #56
- 我的涨分日记(二)——BestCoder Round #59
- 我的涨(diao)分日记(三)——BestCoder Round #63
- 我的涨分日记(四)——BestCoder Round #80
- HDU 5480 Conturbatio(傻傻的我用了线段树)——BestCoder Round #57(div.1 div.2)
- 我的实习日记(一)
- 我的测试日记(一)
- HDU 4908 BestCoder Sequence——BestCoder Round #3
- HDU 5505 GT and numbers(对于被我无意识坑到的3个人我表示抱歉)——BestCoder Round #60
- BestCoder Round #38 ($) —— A
- 我的C++学习日记——变量和基本类型(一)
- 我的求职日记《一》
- 我的JAVA日记 一
- BestCoder Round #36 ($)(一、二题解题报告)
- HDU 5807 BestCoder Round #86 Keep In Touch (分段式DP)
- 爬虫日记(一):我的第一只“爬虫”...
- BestCoder Round #56 (div.2)
- BestCoder Round #15(瞎搞)
- NSString
- 黑马程序员——单例设计模式
- hibernate学习笔记3--事务管理
- 常见oracle 限定查询指令(where 子句)
- [Android]关于RecyclerView控件的使用
- 我的涨分日记(一)——BestCoder Round #56
- Java方法参数传递方式总结
- HDU 5461 Largest Point(2015沈阳赛区网络赛+技巧水题)
- 策略模式(Strategy Pattern)
- PHP重定向三种方法详解
- 技术
- JUnit加载properties配置文件
- 字符串的最小表示法
- JVM 基础 VM运行机制