C - Digital Path

https://nanti.jisuanke.com/t/42397
Zhe the bully, is condemned by all kinds of evil, like bullying those who are weaker. His teammates have been mistreated for a long time. Finally, they decided not to put up with their buddy any more and flee to Digital Village, with the bully in hot pursuit. Due to difficult terrain and a considerable amount of Digital Paths staggered, they can’t be easily arrested.

Getting familiar with the terrain as soon as possible is important for these innocents to escape the threat of bullying. All they need now is to count the number of Digital Paths in Digital Village.

To simplify the problem, Digital Village is abstracted into a grid with
n
rows and
m
columns filled by integers. A Digital Path is a continuous walk in the grid satisfying the following conditions:

adjacent boxes in the walk share a common edge;
the walk is maximal, which cannot be extended;
the walk contains at least four boxes;
going from one end to the other, the increment of values for any two adjacent boxes is exactly one.
Here we have some examples.

The path in Figure 1 is invalid because its length is less than
4
.

The path in Figure 2 is invalid because it is not continuous.

The path in Figure 3 is invalid because it can be extended further.

The path in Figure 4 is also invalid because values in the path are not strictly increased by one.

Digital Paths may partially overlap. In Figure 5, there are
4
Digital Paths marked by different colours.

Input
The first line contains two positive integers
n
and
m

(
1

n
,
m

1000
)
describing the size of the grid.

Each of the next
n
lines contains
m
integers, the
j
-th of which, denoted by
a
i
,
j

(

10
7

a
i
,
j

10
7
)
, represents the value of the box in the
i
-th row and the
j
-th column.

Output
Output the number of Digital Paths modulo
(
10
9
+
7
)
.

Sample Input
3 5
1 2 3 8 7
-1 -1 4 5 6
1 2 3 8 7
Sample Output
4
Sample Input 2
4 4
1 2 3 4
2 3 4 3
3 4 3 2
4 3 2 1
Sample Output 2
16

#include<bits/stdc++.h>
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define endl '\n'
#define ps puts("###")
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn = 1e6+10;
const double eps = 1e-7;
const ll mod = 1e9+7;
const double pi=3.1415926536;
ll t,k,n,m,cnt;
ll a[1010][1010];
ll b[maxn];
ll c[maxn];
ll r[maxn];
ll vis[maxn];
ll p1[maxn],p2[maxn],p3[maxn],p4[maxn];
vector<ll>q[maxn];
void dfs(int i)
{
    ll s=0;
    if(q[i].size()==0)
    {
        p1[i]=1;
        return;
    }
    for(int j=0;j<q[i].size();j++)
    {
        ll u=q[i][j];
        if(vis[u]==0)
        {
            vis[u]=1;
            dfs(u);
        }
        p2[i]+=p1[u];
        p2[i]%=mod;
        p3[i]+=p2[u];
        p3[i]%=mod;
        p4[i]+=(p3[u]+p4[u])%mod;
        p4[i]%=mod;
    }
}
int main()
{
    cin>>n>>m;
    cnt=0;
    for(int i=0;i<=n+1;i++)
    {
        for(int j=0;j<=m+1;j++)
        {
            a[i][j]=-1e9-7;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
            cnt++;
            r[cnt]=0;
            vis[cnt]=0;
            p1[cnt]=0;
            p2[cnt]=0;
            p3[cnt]=0;
            p4[cnt]=0;
            q[cnt].clear();
            b[cnt]=i;
            c[cnt]=j;
        }
    }
    for(int i=1;i<=cnt;i++)
    {
        ll x=b[i];
        ll y=c[i];
        //if(a[x][y]>0)
        {
            if(a[x][y]==a[x-1][y]-1)
            {
                r[i-m]++;
                q[i].push_back(i-m);
            }
            if(a[x][y]==a[x][y-1]-1)
            {
                r[i-1]++;
                q[i].push_back(i-1);
            }
            if(a[x][y]==a[x+1][y]-1)
            {
                r[i+m]++;
                q[i].push_back(i+m);
            }
            if(a[x][y]==a[x][y+1]-1)
            {
                r[i+1]++;
                q[i].push_back(i+1);
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=cnt;i++)
    {
        ll x=b[i];
        ll y=c[i];
        if(r[i]==0)
        {
            vis[i]=1;
            dfs(i);
            ans+=p4[i];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}

<think>好的,我现在需要解决用户提到的OSGi BundleException问题,具体是由于缺少javax.annotation.meta包导致的依赖问题。用户之前已经得到了一些解决方案,但这次又遇到了类似的问题,可能之前的步骤中有遗漏或者新的情况出现。 首先,我要回顾用户之前的问题和我的回答。之前的问题是关于Apache Sling Bundle因缺失javax.annotation.meta包无法启动,我提供了添加依赖、验证Bundle元数据、部署依赖等步骤。现在用户引用了几个新的错误引用,但明确指出要解决同样的问题,所以应该参考之前的解决方案,并结合新的引用内容进行调整。 接下来,查看用户提供的三个新引用。引用1提到了org.protege.common的Bundle错误,缺少org.w3c.dom包,这说明可能是类似的问题,即缺少某个包的依赖。引用2讨论了Spring NamespaceHandler的问题,涉及到Bundle加载顺序和OSGi依赖解析机制,可能需要调整启动顺序或使用start-levels。引用3是Eclipse启动时的Bundle错误,可能与依赖解析或模块冲突有关。 但用户当前的问题仍然是关于javax.annotation.meta的缺失,所以需要专注于这个包的解决方案。需要确保所有步骤都正确应用,特别是添加依赖、检查Import-Package声明以及运行时部署。同时,用户可能遇到的新的情况是,例如依赖版本不兼容,或者Bundle加载顺序的问题,如引用2中提到的启动顺序问题,可能需要调整Bundle的启动顺序或使用start-levels来确保依赖包先加载。 此外,用户可能没有正确配置Maven Bundle插件,导致Import-Package没有自动生成,或者依赖的jar包没有正确打包到Bundle中。需要检查pom.xml配置,确保插件正确设置,并且生成的MANIFEST.MF文件中包含必要的Import-Package语句。 另外,考虑到用户提到的引用3中的Eclipse错误,可能与Eclipse环境中OSGi容器配置有关,可能需要检查Eclipse目标平台配置或使用的OSGi框架版本是否支持所需的包。 最后,需要确认用户是否在运行时环境中正确部署了包含javax.annotation.meta的Bundle,例如通过Apache Karaf安装该Bundle,或者将依赖包放置在正确的目录下。如果用户的环境有多个Bundle相互依赖,可能需要确保所有依赖的Bundle都已正确安装并处于激活状态。 总结步骤:添加依赖、检查Import-Package、部署运行时依赖、处理启动顺序,以及验证环境配置。需要将这些步骤详细说明,并考虑用户可能遇到的其他问题,如版本冲突或配置错误。</think>### OSGi Bundle依赖问题解决方案:缺失`javax.annotation.meta`包 #### 1. **显式添加依赖包** - **Maven/Gradle配置**: ```xml <!-- Maven示例 --> <dependency> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> <version>1.3.2</version> <scope>provided</scope> </dependency> ``` - 若需OSGi兼容版本,建议使用`org.osgi:org.osgi.annotation:6.0.0`[^3]。 #### 2. **验证Bundle导入声明** - 在`MANIFEST.MF`或`bnd.bnd`中确保包含: ``` Import-Package: javax.annotation.meta;version="[1.3,2)" ``` - **Maven Bundle插件自动生成**: ```xml <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <configuration> <instructions> <Import-Package>*, !javax.annotation.meta</Import-Package> <!-- 若自动检测失败,手动添加 --> <_include>javax.annotation.meta;version="[1.3,2)"</_include> </instructions> </configuration> </plugin> ``` #### 3. **运行时部署依赖** - **Apache Karaf/Sling部署命令**: ```bash bundle:install -s mvn:javax.annotation/javax.annotation-api/1.3.2 ``` - 若环境无网络访问,需手动下载并安装: ```bash bundle:install -s file:///path/to/javax.annotation-api-1.3.2.jar ``` #### 4. **处理Bundle启动顺序** - **使用OSGi Start Levels**: ```bash # 设置依赖Bundle的启动级别更低(如20) bundle:start-level org.apache.servicemix.bundles.javax-annotation 20 # 设置主Bundle启动级别更高(如30) bundle:start-level agency-digital-office.core 30 ``` #### 5. **检查Java模块化限制** - **Java 9+环境**:若使用模块路径(JPMS),需在启动参数中开放包: ```bash java --add-opens java.base/javax.annotation.meta=ALL-UNNAMED -jar sling.jar ``` #### 6. **诊断工具辅助排查** - **Karaf命令**: ```bash bundle:diag agency-digital-office.core # 显示具体缺失的依赖 package:exports | grep javax.annotation.meta # 检查该包是否已导出 ``` --- ### 典型错误场景分析 1. **依赖冲突**:若同时存在多个版本的`javax.annotation-api`,使用`bundle:tree`检查依赖树。 2. **Bundle未激活**:通过`bundle:list`确认依赖Bundle状态为`Active`,而非`Installed`。 3. **环境隔离问题**:在Eclipse环境中,需确保`javax.annotation-api`已添加到`target-platform`配置中[^3]。 --- ### 相关问题 1. 如何排查OSGi Bundle的循环依赖问题? 2. 在非Maven项目中如何手动配置OSGi依赖? 3. Sling框架中如何实现Bundle的动态更新?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值