思路:模拟,set记录一下。

#include<set>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
set<int>se;
int n,k,x,ans;
int main(){
freopen("del.in","r",stdin);
freopen("del.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",&x);
if(se.find(x)!=se.end()) k--;
else{
se.insert(x);
ans++;
}
}
if(k<=) cout<<ans<<endl;
else cout<<ans-k<<endl;
}

思路:搜索

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std; int board[][], isKing[][];
int dir[][] = {{, }, {, -}, {-, }, {-, -}};
int best_deep;
vector<int> w;
vector<int> ways; void dfs(int step, int x, int y, int isKing)
{
w.push_back(x * + y);
if (step > best_deep)
{
best_deep = step;
ways.clear();
ways.push_back(w[]);
}
else if (step > && step == best_deep)
{
ways.push_back(w[]);
} int dis_limit = isKing ? : ; for (int d = ; d < ; d++)
{
bool pass = false;
int passx = , passy = ;
for (int dis = ; dis <= dis_limit; dis++)
{
int nxtX = x + dis * dir[d][];
int nxtY = y + dis * dir[d][];
if (!( <= nxtX && nxtX < && <= nxtY && nxtY < ))
break;
if (board[nxtX][nxtY] == || board[nxtX][nxtY] == )
break;
if (pass && board[nxtX][nxtY] == )
break;
if (board[nxtX][nxtY] == )
{
pass = true;
passx = nxtX;
passy = nxtY;
}
else
{
if (!pass)
continue;
board[passx][passy] = ;
dfs(step + , nxtX, nxtY, isKing);
board[passx][passy] = ;
}
}
}
w.pop_back();
} bool getAvailable()
{
ways.clear();
w.clear();
best_deep = ;
for (int curX = ; curX < ; curX++)
for (int curY = ; curY < ; curY++)
if (board[curX][curY] == )
dfs(, curX, curY, isKing[curX][curY]);
if (best_deep == )
{
for (int curX = ; curX < ; curX++)
for (int curY = ; curY < ; curY++)
if (board[curX][curY] == )
{
if (isKing[curX][curY])
{
for (int x = curX + , y = curY + ; <= x && x < && <= y && y < ; x++, y++)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
for (int x = curX + , y = curY - ; <= x && x < && <= y && y < ; x++, y--)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
for (int x = curX - , y = curY + ; <= x && x < && <= y && y < ; x--, y++)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
for (int x = curX - , y = curY - ; <= x && x < && <= y && y < ; x--, y--)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
}
else
{
if (curX - >= && curY - >= && !board[curX - ][curY - ])
ways.push_back(curX * + curY);
if (curX - >= && curY + < && !board[curX - ][curY + ])
ways.push_back(curX * + curY);
}
}
}
if (!ways.size())
return false;
return true;
} int main(){
freopen("chess.in", "r", stdin);
freopen("chess.out", "w", stdout);
memset(board, , sizeof(board));
memset(isKing, , sizeof(isKing));
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
{
char c;
scanf(" %c", &c);
board[i][j] = c - '';
}
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
{
char c;
scanf(" %c", &c);
isKing[i][j] = c - '';
}
getAvailable();
if (!ways.size())
printf("0\n");
else {
sort(ways.begin(), ways.end());
printf("%d\n", (int)ways.size());
for (int i = ; i < (int)ways.size(); i++)
printf("(%d,%d)\n", ways[i] / + , ways[i] % + );
}
}

思路:状压DP.

对后续决策有影响的是什么?

现在已经吃了哪些馅饼

令F[i][s]表示考虑前i次馅饼掉落事件,吃了s这个二进制状态表示的馅饼,期望的美味值

对于每一次掉馅饼,枚举掉下来的馅饼是谁

若s&a[j]==a[j](a[j]为前提馅饼集合) F[i][s] -> F[i+1][s|(1<<(j-1))] 注意要 /n

递推的顺序?

一个起始状态,多个目标状态,正推会导致无效状态

反着推

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,x,y;
int w[],f[];
double dp[][];
int main(){
freopen("bonus.in","r",stdin);
freopen("bonus.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=;i<n;i++){
scanf("%d",&w[i]);
while(scanf("%d",&x)&&x) f[i]|=<<x-;
}
for(int s=;s<(<<n);s++) dp[k][s]=;
for(int i=k-;i>=;i--)
for(int s=;s<(<<n);s++)
for(int j=;j<n;j++)
if((s&f[j])==f[j]) dp[i][s]+=1.0/n*max(dp[i+][s],dp[i+][s|(<<j)]+w[j]);
else dp[i][s]+=1.0/n*dp[i+][s];
printf("%.6f\n",dp[][]);
}

最新文章

  1. 【04-10】java中的路径
  2. 利用session_set_save_handler()函数将session保存到MySQL数据库中
  3. RHEL 6.0服务器安装Oracle 11G R2 最终版
  4. myeclipse使用maven插件进行maven install时报错check $m2_home environment variable and mvn script match
  5. R-处理数据对象的实用函数
  6. ehcache的介绍和使用
  7. Xcode can&#39;t verify the identity of the server
  8. c31 rotc_百度百科
  9. Git 基本原理与经常使用命令
  10. Spring - 运行时获取bean(ApplicationContextAware接口)
  11. 部分小程序无法获取UnionId原因
  12. C语言课程设计(成绩管理系统)
  13. Promise(避免金字塔回调)
  14. C++中字符串换行(如何拆分为多行)
  15. x264编码的图像出现乱码的问题
  16. MyEclipse文本对比界面样式修改
  17. 操作系统基础梳理--进程&amp;线程
  18. php phpmail发送邮件的效果
  19. Thread.Sleep(1000) 、Task.Delay(1000).Wait() 区别
  20. ethereumjs/ethereumjs-vm-1-简介

热门文章

  1. [读书笔记] Python数据分析 (二) 引言
  2. VUE:事件处理和表单输入绑定
  3. C语言 将十六进制字符串转为十六进制数 (二进制、十进制都适用)
  4. thinkphp 多个字段的不同关系的查询条件实现 .
  5. MarkDown、Vim双剑合璧
  6. USACO 5.1.1凸包
  7. Android与server通信的方法之中的一个(json)效率不高安全性不好
  8. @dynamic与@synthesize的差别
  9. node11---相册
  10. 关于输入getline