- 博客(11)
- 资源 (9)
- 收藏
- 关注
原创 离散0-1背包问题 采药(之前弄混了一次,这次不要弄混了,在考虑第i个物品的时候,不考虑之前的物品是否放)
#include <stdio.h>#include <iostream>using namespace std;struct N{ int w,v;};N list[101];int dp[101][1001];int max(int a,int b){ return a>b?a:b;}int main(){ int max_...
2018-04-17 09:55:19 314
原创 greedy tino(教训!)
贪婪的tino#include <stdio.h>#include <string.h>#include <iostream>using namespace std;#define INF 0x7fffffff#define OFFSET 2000int dp[101][4001];int list[101];int max(int a,i...
2018-04-17 00:37:02 239
原创 p166 搬寝室 注意list的下标是从1开始的,(1)在sort的时候(2)在写状态转移公式的时候
我跟书上写的不一样,但是我的可以过,好理解。。#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <queue>#include <stack>using namespace std;//注意...
2018-04-14 11:11:32 1832
原创 最长公共子序列LCS
新问题:下标的问题,字符串的下标是从0开始的,使用dp的下标是从1对应的是字符串的0。还是原来的sb问题,输入使用scanf前面两个%s后面只有一个s1没有了s2。#include <stdio.h>#include <string.h>#include <iostream> using namespace std;char s1[105],s2[1...
2018-04-13 21:49:00 306
原创 p160 LIS 最长递增子序列
#include <stdio.h>#include <iostream>using namespace std;int ans[26];int list[26];int main(){ int k; while(scanf("%d",&k)!=EOF) { for(int i=1;i<=k;i++) { scanf("%...
2018-04-11 09:08:35 129
原创 p159 不容易系列之一(同上)
#include <stdio.h>using namespace std;long long ans[21];int main() { ans[1]=0; ans[2]=1; for(int i=3;i<=21;i++) { ans[i]=(i-1)*ans[i-1]+(i-1)*ans[i-2];//手一抖又写错了!!!啊啊啊 } ...
2018-04-11 08:51:45 199
原创 p157 N阶楼梯上楼问题 斐波那契数列 dp的最简单的应用
#include <stdio.h>long long ans[100];//注意这里必须使用lld保存数据!!int main(){ ans[1]=1; ans[2]=2; for(int i=3;i<=100;i++) { ans[i]=ans[i-1]+ans[i-2]; } int n; while(scanf("%d",&n)!=EO...
2018-04-11 08:42:11 293
原创 p133 BFS 广搜,队列
在BFS中go数组的下标从1开始了!!其实应该从0开始啊,不知道我是怎么想的。在三层循环赋值的时候把里层的k写成了j。。#include <stdio.h>#include <string.h>#include <queue>using namespace std;struct N{ int x,y,z,t;}; int maze[51][5...
2018-04-09 21:47:58 127
原创 p132 百鸡问题 关键在于约束条件,每一个循环的约束条件!
一定要在纸上推出来之后再打出来!关键在于约束条件,每一个循环的约束条件!#include <stdio.h> using namespace std;//程序出错了,先不要想着调试,先找出一些傻缺的错误!然后找出一些关键性的错误。要知道自己容易犯的错误时哪些! int main(){ int n; while(scanf("%d",&n)!=EOF) { ...
2018-04-09 18:19:28 185
原创 p127 拓扑排序 leagal or not?
输入两个变量只用了一个%d我怎么这么傻啊天哪啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊#include <stdio.h>#include <queue>#include <vector>using namespace std;queue<int> Q...
2018-04-09 10:13:09 140
原创 c++中的vector用法
不断积累,用过才能叫会。向量就像一个list,一个可变的数组。1.最基本的vector<int> qq;qq.push_back(...);压入向量qq.pop_back();弹出 最后一个元素qq.size()表示向量数组的大小qq.begin(); qq.end();可以用来排序...
2018-04-09 09:01:58 115
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人