随笔分类 -  动态规划

摘要:/* 调了半晚上了...... 感觉是凑出来的QAQ 不过也还好思路比较清晰 数位dp f[i]表示i位的二进制数中 有几个合法的(默认开头一个是1) 然后求[1,L] [1,R+1] 首先位数小的都行 关键是位数一样的 这里还要保证数值比他小 比如 110100循环高位到低位 变成 10****统计****位的就好了 这样就保证比他小 程序里那两个reverse啥的可以无视 后期写的蒙蔽... 阅读全文
posted @ 2016-10-10 21:57 一入OI深似海 阅读(184) 评论(0) 推荐(0)
摘要:/* 这题卡常数.... 二进制优化或者单调队列会被卡 必须+上个特判才能过QAQ 单调队列维护之前的钱数有几个能拼出来的 循环的时候以钱数为步长 如果队列超过c[i]就说明队头的不能再用了 拿出来 时刻维护sum表示之前的+v[i]能凑出j来的有几种 注意先进队在更新f */ #include #include #include #define maxm 100010 #define max... 阅读全文
posted @ 2016-10-08 22:29 一入OI深似海 阅读(288) 评论(1) 推荐(1)
摘要:/*bzoj 1613*/ /*暴力5884ms*/ #include #define maxn 10010 using namespace std; int n,m,a[maxn],f[maxn][510]; int max(int x,int y){ return x>y?x:y; } int main() { scanf("%d%d",&n,&m); for(int... 阅读全文
posted @ 2016-09-29 22:12 一入OI深似海 阅读(352) 评论(0) 推荐(0)
摘要:/* n*n暴力 这个很好想 */ #include #define maxn 100010 #define mod 9901 using namespace std; int n,k,a[maxn],f[maxn],ans; int Abs(int a){ return ak)continue; f[i]=(f[i]+f[j]+1)%mod; ... 阅读全文
posted @ 2016-09-20 09:07 一入OI深似海 阅读(309) 评论(0) 推荐(0)
摘要:/*暴力50*/ #include #include #include #define maxn 100010 #define ll long long using namespace std; ll n,k,f[maxn][110],a[maxn],ans; ll init(){ ll x=0,f=1;char s=getchar(); while(s'9'){if(s=='-... 阅读全文
posted @ 2016-09-17 22:25 一入OI深似海 阅读(301) 评论(0) 推荐(0)
摘要:/* 开始暴力+滚动数组70 后来发现不用循环很多 找p的倍数 找%p意义下为0的就好了 */ #include #include #include #define maxn 3010 #define mod 1000000009 using namespace std; int n,p,a[maxn],f[2][maxn],sum,ans; int main() { scanf("%... 阅读全文
posted @ 2016-09-17 22:22 一入OI深似海 阅读(226) 评论(0) 推荐(0)
摘要:#include #include #include #define mod 100000000 #define maxn 5010 using namespace std; int l1,l2,f[maxn][maxn],s[maxn][maxn]; char s1[maxn],s2[maxn]; int main() { freopen("lcs.in","r",stdin); ... 阅读全文
posted @ 2016-09-08 22:30 一入OI深似海 阅读(242) 评论(0) 推荐(0)
摘要:/* 很容易想到f[i][j][k][l][01] 表示到ij点 两个人得分为kl 01表示这一步谁走的 因为起点不同 路径不同 所以要枚举起点.. 时间复杂度 O(nmk*nmk) 空间复杂度 O(2*nmkk) 超时爆空间..... 40分 */ #include #include #include #define maxn 810 #define mod 1000000007 usi... 阅读全文
posted @ 2016-08-27 15:12 一入OI深似海 阅读(364) 评论(0) 推荐(0)
摘要:/*每个环 要么不选 要么全选 可缩点 就得到一个GAD图 然后搞搞算出最大路径*/ #include #include #include #define maxn 100010 using namespace std; int T,n,m,num,head[maxn],low[maxn],dfn[maxn],s[maxn],top,vi[maxn]; int sum,belong[maxn],... 阅读全文
posted @ 2016-08-24 09:16 一入OI深似海 阅读(248) 评论(0) 推荐(0)
摘要:/*机智sort二维转一维*/ #include #include #include #include #define maxn 50010 using namespace std; int n,s,num,c[maxn*6]; struct node { int l,r; }a[maxn*6]; int cmp(const node &x,const node &y) { if... 阅读全文
posted @ 2016-08-17 20:09 一入OI深似海 阅读(180) 评论(0) 推荐(0)
摘要:/* 表示很遗憾.. 开始状态想的没错 就是转移的时候出了问题 自己也想到了数组平移 然而没往下写 与正解擦肩而过…. 然后为了好转移写了个4维的 时间不多了没来得及降维 草草的算算空间就交了… 尼玛double忘记*8了 华丽的直接Memory limit exceeded while compiling 我尼玛0分 考试后写了写用原来的状态写了写数组平移然后降维 数据太水就A了 */ #i... 阅读全文
posted @ 2016-08-17 19:58 一入OI深似海 阅读(157) 评论(2) 推荐(0)
摘要:这题之前做过…先听后做的 所以直接打了优化的dp、 然而不是自己想的方法还是理解的不好 一直75分 wa到挺 今天考试看到暴力dp70分 很自信加上点 continue break啥的就80+了 比优化的dp得分多 机智的我哈哈哈….. 然而手残了..枚举k次蹦跶结果转移的时候我特么都是+1不是+k 悲伤的我眼泪掉下来….. 然后改过来就80了 又不好办了.. 下面是80分代码 #include... 阅读全文
posted @ 2016-08-17 19:57 一入OI深似海 阅读(304) 评论(0) 推荐(0)
摘要:/* 好神奇好神奇...表示自己要学的还很多 注意到n #include #include #define maxn 520 using namespace std; int n,K,v1[maxn],v2[maxn][maxn],cnt[maxn]; long long ans,f[10][100][maxn]; void Get_v() { for(int i=0;i>1))==0)... 阅读全文
posted @ 2016-08-15 21:38 一入OI深似海 阅读(336) 评论(0) 推荐(0)
摘要:/* 一开始想的二维的 只维护第几只牛还有圈数 后来发现每只牛的能量是跟随每个状态的 所以再加一维 f[i][j][k]表示第i只牛 领跑的j全 已经消耗了k体力 转移的话分两类 1.换一只牛领跑 那么就从f[i][j][k]转移到f[i+1][j][j] 2.不换 那就枚举i领跑几圈l f[i][j-l][k-l*l]转移到f[i][j][k] 时间++ */ #include #inc... 阅读全文
posted @ 2016-08-14 16:36 一入OI深似海 阅读(301) 评论(0) 推荐(0)
摘要:/* 一开始并没有想出On的正解 后来发现题解的思路也是十分的巧妙的 还是没能把握住题目的 只有1 2这两个数的条件 dp还带练练啊 ... */ #include #include #include #define maxn 100010 using namespace std; int n,a[maxn],Q[maxn],H[maxn],ans=0x7fffffff; int main()... 阅读全文
posted @ 2016-08-14 11:19 一入OI深似海 阅读(196) 评论(0) 推荐(0)
摘要:/* 需要好大的空间..... 而且lowbit理解的不是很好 先放到博客里 以后慢慢研究 */ #include #include #include #include #define inf 999999999; #define maxn 1050000 using namespace std; int n,a[maxn]; double x[30],y[30],g[30][30],f[m... 阅读全文
posted @ 2016-08-14 09:57 一入OI深似海 阅读(176) 评论(0) 推荐(0)
摘要:/* f[i][j] 表示走过的点构成i状态 且最后到达的点为j时的最优解 在那最后一个状态就是(1 #include #include #define maxn 100010//最少到 1<<16 using namespace std; int n,g[20][20],f[maxn][20],ans=0x3f3f3f3f; int main() { scanf("%d",&n); ... 阅读全文
posted @ 2016-08-13 18:22 一入OI深似海 阅读(212) 评论(0) 推荐(0)
摘要:/*10分钟的暴力 意料之中的5分..*/ #include #include #include #define maxn 1010 using namespace std; int n,m,p,g[maxn][maxn],w[maxn],ans; void Dfs(int now,int v) { if(now>m){ans=max(ans,v);return;} for(in... 阅读全文
posted @ 2016-08-06 22:21 一入OI深似海 阅读(936) 评论(0) 推荐(0)
摘要:/* 状态f[i][j][k] 表示A串匹配到i B串匹配到j 用了k个子串 转移的话 f[i][j][k]=f[i-1][j-1][k]+f[i-1][j-1][k-1]分别表示i是不是建立了一个新的子串 当然这是我们会发现 这样的状态是默认了i用了 显然i可以不用 也就是说这样就遗漏了许多状态 我们重新定义一下他 加一维01表示i用了没用 f[i][j][k][0或1] 这样转移就要分开考虑... 阅读全文
posted @ 2016-08-02 19:53 一入OI深似海 阅读(1155) 评论(1) 推荐(0)
摘要:/*先贴个n*n的*/ #include #include #include #define maxn 1000010 using namespace std; int n,k,h[maxn],f[maxn],Q; int main() { scanf("%d",&n); for(int i=1;i=h[j])f[i]=min(f[i],f[j]+1); ... 阅读全文
posted @ 2016-07-25 19:21 一入OI深似海 阅读(161) 评论(0) 推荐(0)