HDU - 4804 Campus Design 轮廓线dp

本文介绍了一个关于矩阵被特定尺寸骨牌完全覆盖的问题,并通过动态规划的方法给出了详细的解决方案。问题要求一个n*m的矩阵使用1*2和1*1的骨牌进行覆盖,同时考虑了骨牌的数量限制及矩阵中的障碍物。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:一个nm的矩阵被12的骨牌和11的骨牌完全覆盖,11的骨牌只能放c-d次,矩阵中有障碍物
题解:dp[i][j][k]表示到了第i行,第j个状态,放过k个11的骨牌,当前位有障碍物时只有一种转移就是放当前点,当前位无障碍物时转移有四种,向上放,向下放,不放,放11的

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double eps=1e-6;
const int N=(1<<11)+10,maxn=5000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

int n,m,c,d;
char s[100+10][10+10];
int dp[2][N][25];
inline void add(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void solve()
{
    memset(dp,0,sizeof dp);
    int now=0,pre=1;
    dp[now][(1<<m)-1][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            swap(now,pre);
            memset(dp[now],0,sizeof dp[now]);
            if(s[i][j]=='0')
            {
                for(int k=0;k<(1<<m);k++)
                    for(int l=0;l<=d;l++)
                        if(k&(1<<(m-1)))
                            add(dp[now][((k<<1)^(1<<m))|1][l],dp[pre][k][l]);
            }
            else
            {
                for(int k=0;k<(1<<m);k++)
                {
                    for(int l=0;l<=d;l++)
                    {
                        if(i && (!(k&(1<<(m-1)))))
                            add(dp[now][(k<<1)|1][l],dp[pre][k][l]);
                        if(j && (k&(1<<(m-1))) && (!(k&1)))
                            add(dp[now][((k<<1)^(1<<m))|3][l],dp[pre][k][l]);
                        if(k&(1<<(m-1)))
                        {
                            add(dp[now][(k<<1)^(1<<m)][l],dp[pre][k][l]);
                            add(dp[now][((k<<1)^(1<<m))|1][l+1],dp[pre][k][l]);
                        }
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=c;i<=d;i++)add(ans,dp[now][(1<<m)-1][i]);
    printf("%lld\n",ans);
}
int main()
{
    while(~scanf("%d%d%d%d",&n,&m,&c,&d))
    {
        for(int i=0;i<n;i++)scanf("%s",s[i]);
        solve();
    }
    return 0;
}
/********************

********************/

转载于:https://www.cnblogs.com/acjiumeng/p/9094244.html

### MCP in Python Usage and Implementation #### Overview of MCP in Python The Model Context Protocol (MCP) is a protocol designed to facilitate interactions between AI models and external tools, data sources, or APIs[^3]. In the context of Python, MCP can be implemented using the MCP Python SDK, which provides tools for building both servers and clients. This implementation allows developers to interact with MCP bridges or agents effectively. #### Installing MCP Python SDK To integrate MCP into Python projects, the MCP Python SDK can be installed via pip: ```bash pip install mcp ``` This command installs the necessary libraries for interacting with MCP servers or clients[^1]. #### Configuring MCP Server in Python A MCP server can be configured in Python by defining its behavior and endpoints. Below is an example of setting up a basic MCP server using Python: ```python from mcp.server import MCPServer def handle_request(data): # Process incoming request data return {"result": "Processed"} if __name__ == "__main__": server = MCPServer(handle_request, port=8080) server.start() ``` In this example, the `MCPServer` class initializes a server that listens on port 8080 and processes incoming requests by calling the `handle_request` function[^1]. #### Configuring MCP Client in Python For interacting with an existing MCP server, a client can be set up as follows: ```python from mcp.client import MCPClient client = MCPClient(mcp_url="http://localhost:8080", mcp_port=8080) response = client.send_request({"action": "fetch_data"}) print(response) ``` Here, the `MCPClient` sends a request to the MCP server at the specified URL and port, and retrieves the response[^2]. #### Advanced Configuration Options MCP servers and clients can be further customized with additional parameters such as JSON formatting, logging levels, and security settings. For instance: ```python client = MCPClient( mcp_url="http://localhost:8080", mcp_port=8080, hide_json=True, json_width=120 ) ``` This configuration hides JSON results from tool executions and sets the maximum width for JSON output to 120 characters. #### Integration with Databases MCP can also be integrated with databases to enhance data retrieval and model interaction. This approach offers advantages over traditional RAG methods by providing more efficient and precise data access[^4]. An example of integrating MCP with a database might look like this: ```python from mcp.server import MCPServer import sqlite3 def fetch_data_from_db(query): conn = sqlite3.connect("example.db") cursor = conn.cursor() cursor.execute(query) result = cursor.fetchall() conn.close() return result def handle_request(data): query = data.get("query") if query: return {"data": fetch_data_from_db(query)} return {"error": "No query provided"} if __name__ == "__main__": server = MCPServer(handle_request, port=8080) server.start() ``` This script sets up an MCP server that executes SQL queries against a SQLite database[^4]. #### Best Practices for MCP Implementation - Ensure secure communication between MCP clients and servers using authentication mechanisms. - Optimize performance by configuring appropriate logging levels and resource limits. - Test the MCP implementation thoroughly to handle edge cases and errors gracefully.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值