摘要: 想到了用背包 一开始没想到怎么做,后来又因为细节出错了。。应该用在每个状态将每种布快形状都先考虑放入,这样可以保证之后的状态可以是从之前最优的推出。。如果换个写法就不行了#include #include #include #include #include #include #include using namespace std;int dp[1105][1105];struct TH{ int x, y, c;} th[25];int main(){ int i, j, k, T, n, x, y, a, b, c; scanf("%d",&T); while 阅读全文
posted @ 2013-10-30 10:42 Ink_syk 阅读(177) 评论(0) 推荐(0) 编辑
摘要: - -比赛时用了很奇怪的方法 然后最后评判TLE了。。。。 赛后中规中矩的用线段树过了#include #include #include #include using namespace std;int kn[300005], len[300005];struct segTree{ int l, r, va;} seg[300005>1; build(l,m,rt>1; if(lm) change(l,r,rt>1; if(xm) cg(x,rt<<1|1); seg[rt].va=0;}void update(int l,int r,int rt){ i... 阅读全文
posted @ 2013-10-16 10:46 Ink_syk 阅读(321) 评论(0) 推荐(0) 编辑
摘要: 一道简单的拓扑排序,因为优先选小的所以用了优先队列#include#include#include#include#includeusing namespace std;vector eg[505];int ans[505], ct[505];struct Node{ bool operator b.va; } int va; Node(){} Node(int x){va=x;}} ;priority_queueq;int main(){ int i, j, n, m, now, a, b; while(scanf("%d%d",&n,&m)!=EO... 阅读全文
posted @ 2013-09-11 18:37 Ink_syk 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 网上搜的题解除了暴搜就是二分图匹配 我试了下用状态压缩做做。。。比较乱来#include #include #include #include using namespace std; char map[5][5]; int n, num; int sta[5][21], the[5][21], l[5], dp[5][21]; void deal(int x) { int i, j, tmp, p, q; bool f, r; for(i=0; i<num; i++) { j=0; p=i; f=true; ... 阅读全文
posted @ 2013-09-06 08:07 Ink_syk 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 今天突然想做道题, 区域赛的题对于我来讲还是不简单的。。。 代码一多 写的看起来就挫了。。。看网上说是状态压缩DP,看了下数据,Y+G小于等于15 好吧,看来确实是这样,一开始还在想难道可以用搜索?状态压缩DP一直习惯于从通过前面的状态来更新当前状态,写的有些混乱。。。 下次试试从当前状态更新到下一个状态。。。把所有的Y点和G点编号,求出各个点之间的距离,如果Y点某点与起点不连通,说明无解,否则有解DP 遇到G则步数变为0,参考别人是用二分查找求解的 我也就这么做了。。。#include#include#include#include#includeusing namespace std;co 阅读全文
posted @ 2013-09-01 16:12 Ink_syk 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 状态压缩DP,被字典序坑了10几分钟。。。。。。。#include #include using namespace std; const int INF=10; j-=j&(-j)) { tmp=j&(-j); xx=p[tmp]; if(dp[i^tmp].alt+sub[xx].t>sub[xx].ed) now=dp[i^tmp].alt+sub[xx].t-sub[xx].ed; else no... 阅读全文
posted @ 2013-08-29 13:11 Ink_syk 阅读(136) 评论(0) 推荐(0) 编辑
摘要: DP,比较容易想到是2维DP,表示到第一个字符串的i和第二个字符串的j最大值是多少, 字符串下标的0在这里对应的i,j是1#include #include #include #include using namespace std; const int INF=-(1<<29); char s1[105], s2[105]; int dist[151][151], dp[105][105]; void init() { dist['A']['A']=5; dist['A']['C']=dist['C' 阅读全文
posted @ 2013-08-28 09:42 Ink_syk 阅读(116) 评论(0) 推荐(0) 编辑
摘要: DP大水题。。关键是路径记录#include #include #include using namespace std; const int INF=11) puts(""); memset(vis,0,sizeof(vis)); memset(can,0,sizeof(can)); memset(path,-1,sizeof(path)); scanf("%d",&n); for(i=1;i=0) dp[i]=maxv+in[i]; } ans=-... 阅读全文
posted @ 2013-08-27 15:33 Ink_syk 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 第二道状态压缩。。。 自己做出来还是很爽的二维, 第一维表示当前状态, 第二维表示当前地点。先从未达到tt这个点的状态推出当前有tt状态的点,然后再根据同状态其他已到达点 试着从其他点更新到该点,使得时间更小。#include #include #include using namespace std; int map[12][12], dp[1333][11], p[12]; const int INF=10; j-=j&(-j)) { tt=j&(-j); for(r=0; r<=n; r++) ... 阅读全文
posted @ 2013-08-27 13:40 Ink_syk 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 第一道状态压缩DP。。。。入门题 按照自己的思路来 AC了先把每行可行的状态求出来 再进行DP#include #include #include using namespace std; const int mod=100000000; int dp[13][5000], map[13][13], state[13][1005], len[13]; int main() { int n, m, i, j, k; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) for(j=0;... 阅读全文
posted @ 2013-08-27 11:56 Ink_syk 阅读(110) 评论(0) 推荐(0) 编辑